PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ibnclaudius
Forum Newbie
Posts: 12 Joined: Thu Dec 08, 2011 7:41 pm
Post
by ibnclaudius » Thu Dec 08, 2011 8:49 pm
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);
}
}
?>
twinedev
Forum Regular
Posts: 984 Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio
Post
by twinedev » Thu Dec 08, 2011 10:23 pm
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
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Fri Dec 09, 2011 1:22 am
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();
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ibnclaudius
Forum Newbie
Posts: 12 Joined: Thu Dec 08, 2011 7:41 pm
Post
by ibnclaudius » Fri Dec 09, 2011 2:31 am
I changed:
to
Code: Select all
echo "$_SESSION['userEnrollment']"; to
to
But ajax_login.php still gives me a blank page, even with no dbInfo setted. Should give a MySQL error...
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Fri Dec 09, 2011 2:48 am
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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ibnclaudius
Forum Newbie
Posts: 12 Joined: Thu Dec 08, 2011 7:41 pm
Post
by ibnclaudius » Fri Dec 09, 2011 7:23 am
I turned on the error report. And made the changes you said (var -> public), now its okay.
Thanks for your help!