Page 1 of 1

Login system gives blank page

Posted: Thu Dec 08, 2011 8:49 pm
by ibnclaudius
ajax_login.php gives a blank page...

login.php

Code: Select all

<form method="post" action="ajax_login.php">

	Matrpicula: <input type="text" name="userEnrollment" maxlength="32"><br>

	Senha: <input type="password" name="userPass" maxlength="32"><br>

	<input type="submit">

</form>
ajax_login.php

Code: Select all

<?


session_start();


include 'class/network.php';



$D = new network;



$D->userEnrollment = mysql_real_escape_string($_POST['userEnrollment']);

$D->userPassword = hash('sha512', $_POST['userPass']);



$D->userLogin();

echo "$_SESSION['userEnrollment']";



?>
class/network.php

Code: Select all

<?



	class network {



		var $userID,

			$userEnrollment,

			$userPass,

			$dbHost,

			$dbUser,

			$dbName,

			$dbPass,

			$dbUserTable;



		function dbInfo() {

			$this->dbHost = 'localhost';

			$this->dbUser = 'user';
			$this->dbPass = 'pass';

			$this->dbName = 'dbname';

			$this->dbUserTable = 'usertable';

		}

	

		function userLogin() {

			$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);

			if(!$dbLink) die("Could not connect to database: " . mysql_error());



			mysql_select_db($this->dbName);



			$query = "SELECT * FROM $this->dbUserTable WHERE userEnrollment = \"$this->userEnrollment\" AND userPass = \"$this->userPass\" LIMIT 1";

			$result = mysql_query($query);

		

			if(!$result) {

				echo "Fail.";

			} else {

				$row = mysql_fetch_array($result))

				session_regenerate_id();

					$_SESSION['userEnrollment'] = $this->userEnrollment;

				session_write_close();

			}



			mysql_close($dbLink);

		}


		

	}

?>

Re: Login system gives blank page

Posted: Thu Dec 08, 2011 10:23 pm
by twinedev
My guess would be the fact that close and end the session right after you assign a value to it, so it would be available later to echo out.

Not sure, never used session_write_close() before, but looking it up, that would be my best guess.

-Greg

Re: Login system gives blank page

Posted: Fri Dec 09, 2011 1:22 am
by social_experiment
Not sure if this is related but you're missing parenthesis on your object instantiation

Code: Select all

<?php
$D = new network;
// should be
$D = new network();
?>

Re: Login system gives blank page

Posted: Fri Dec 09, 2011 2:31 am
by ibnclaudius
I changed:

Code: Select all

<?
to

Code: Select all

<?php

Code: Select all

echo "$_SESSION['userEnrollment']";
to

Code: Select all

echo $_SESSION['userEnrollment'];

Code: Select all

$D = new network;
to

Code: Select all

$D = new network();
But ajax_login.php still gives me a blank page, even with no dbInfo setted. Should give a MySQL error...

Re: Login system gives blank page

Posted: Fri Dec 09, 2011 2:48 am
by social_experiment

Code: Select all

<?php
 var $userID,

                        $userEnrollment,

                        $userPass,

                        $dbHost,

                        $dbUser,

                        $dbName,

                        $dbPass,

                        $dbUserTable;
?>
Are the class properties part of an array?

Code: Select all

<?php
// try this approach for all your class properties
public $userEnrollment;
// etc, etc
?>
It is possible that error reporting is turned off on your php version. Have a look at this url http://php.net/manual/en/function.error-reporting.php

Re: Login system gives blank page

Posted: Fri Dec 09, 2011 7:23 am
by ibnclaudius
I turned on the error report. And made the changes you said (var -> public), now its okay.

Thanks for your help!