durian durian - 6 months ago 17
PHP Question

session register doesnt work

im having a problem with registering sessions on my websites login script:
so the thing is like this, im working on my site with webmatrix and i worked on the same files on two different computers, also I have the site uploaded to a server. in all three cases it works just fine!
recently i created the very same working inviorement on a laptop i have, webmatrix + xampp mysql db - only here i found out that sessions refuse to be created, the code:

(the login page is included in the index.php page.

<?php
session_start();
$no_mail_pass_error="";
$no_user_error="";
$wrong_pass_error="";

if ($_POST['submit_login']){

$log_email = $_POST ["log_email"]; //VAR $email = to what usename has entered
$log_password = $_POST ["log_password"]; //VAR $password = to what usename has entered
$remember_me = $_POST ["remember_me"];

$log_email = strip_tags($log_email);
$log_password = strip_tags($log_password);

$log_email = mysql_real_escape_string($log_email);
$log_password = mysql_real_escape_string($log_password);

if ($log_email==""||$log_password=="") {
$no_mail_pass_error='
<div id="login_errors_div" style="display:none;">
<table border="0">
<tr>
<td>
<img src="ec_mark_25.png"/>
</td>
<td>
no mail
</td>
</tr>
</table>
<hr />
</div>

';
}
else {

$login_connect = mysql_connect ("***", "***", "***")

or die ("couldnt connect");
mysql_select_db (***) or die ("not found"); //if db was not found die
mysql_query("SET NAMES 'utf8'");

$login_query = mysql_query("SELECT * FROM users WHERE email='$log_email'"); //search for specific username entered

$login_numrows = mysql_num_rows($login_query); //check that it appears AT LEAST in ONE row

if ($login_numrows!=0) // IF IT APPEARS IN NONE - NO USER EXISTS

{

while ($row = mysql_fetch_assoc($login_query)) //Takes the whole row of the specific user and extracts all the fields
{
$dbemail = $row['email'];
$dbpassword = $row['password']; //Sets thoes fields into variables
$id = $row['id'];
$log_firstname = $row['firstname'];
$log_lastname = $row['lastname'];
}

if ($log_email==$dbemail&&md5($log_password)==$dbpassword)

{

if ($remember_me=='on') {
setcookie ("email",$email,time()+604800);

session_register('email');
$_SESSION['email']=$log_email;

session_register('id');
$_SESSION['id']=$id;

session_register('firstname');
$_SESSION['firstname']=$log_firstname;

session_register('lastname');
$_SESSION['lastname']=$log_lastname;

header ("Location: homepage.php");
}
else if ($remember_me=='') {

session_register('email');
$_SESSION['email']=$log_email;


session_register('id');
$_SESSION['id']=$id;

session_register('firstname');
$_SESSION['firstname']=$log_firstname;

session_register('lastname');
$_SESSION['lastname']=$log_lastname;


header ("Location: homepage.php");
}

}
else {
$wrong_pass_error='
<div id="wrong_pass_error_div" style="display:none;">
<table border="0">
<tr>
<td>
<img src="ec_mark_25.png"/>
</td>
<td>
wrong pass
</td>
</tr>
</table>
<hr />
</div>
';
}


}

else {
$no_user_error='
<div id="no_user_error_div" style="display:none;">
<table border="0">
<tr>
<td>
<img src="ec_mark_25.png"/>
</td>
<td>
user not found
</td>
</tr>
</table>
<hr />
</div>
';
}

}



}
?>
<form name="login_form" id="logn_form" method="post" action="index.php">
<table border="0" style="margin-left: 60px; margin-bottom: 3px;">

<tr>

<td id="login_info">mail</td>
<td id="login_info">pass</td>
<td></td>
</tr>

<tr>
<td><input id="login_input" name="log_email" type="text"/></td>
<td><input id="login_input" name="log_password" type="password"/></td>
<td><input id="login_submit" name="submit_login" type="submit" value="enter"/></td>
</tr>

<tr>
<td valign="top">
<!-- TABLE FOR REMEMBER ME -->
<table style="margin: 0px; padding:0px;"><tr>
<td>
<input name="remember_me" type="checkbox"/>
</td>
<td>remember me</td>
</tr></table>
<!-- TABLE FOR REMEMBER ME - END -->
</td>
<td valign="top"><div style="margin-top: 5px; margin-right: 5px;"><a id="forgot_password_a" href="#">forgot pass</a></div></td>
</tr>
</table>
</form>


what could be preventing the sessions from registering?? can some one please advice?

dbf dbf
Answer

Posting my comment as an answer ;)

Check your PHP version (I believe they differ from both environments).

session_register has been deprecated as of PHP 5.3 and in PHP >= 5.4 removed. Just remove session_register and use $_SESSION['key'] = "value"; instead.

See session_register docs.