我在网站登录脚本上注册会话时遇到问题: 所以事情是这样的,我正在使用webmatrix在我的网站上工作,我在两台不同的计算机上处理相同的文件,我也将网站上传到服务器。在所有三种情况下,它工作得很好! 最近我在笔记本电脑上创建了相同的工作环境,webmatrix + xampp mysql db - 只有在这里我发现会话拒绝创建,代码:
(登录页面包含在index.php页面中。
<?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>
什么可能阻止会话注册?
答案 0 :(得分:4)
发表评论作为答案;)
检查您的PHP版本(我相信它们与这两种环境不同)。
自PHP 5.3起, session_register
已被弃用,并且已删除PHP&gt; = 5.4。只需删除session_register
并使用$_SESSION['key'] = "value";
代替。
请参阅session_register文档。
答案 1 :(得分:0)
检查PHP保存会话数据的位置。你可以用phpinfo()找到它,你可以在php.ini中更改它。我认为它叫做session.save_path,并确保apache用户(或任何Web服务器)具有对该目录的写访问权。