1

我在我的网站登录脚本上注册会话时遇到问题:所以事情是这样的,我正在使用 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>

什么可能阻止会话注册?

4

2 回答 2

4

发表我的评论作为答案;)

检查您的 PHP 版本(我相信它们与两种环境都不同)。

session_register自 PHP 5.3 起已弃用,并在 PHP >= 5.4 中删除。只需删除session_register$_SESSION['key'] = "value";改用即可。

请参阅session_register文档。

于 2012-10-27T23:45:10.983 回答
0

检查 PHP 保存会话数据的位置。您可以使用 phpinfo() 找到它,并且可以在 php.ini 中更改它。我认为它称为 session.save_path,并确保 apache 用户(或任何 Web 服务器)具有对该目录的写入权限。

另请查看http://php.net/manual/en/function.session-save-path.php

于 2012-10-27T22:26:53.080 回答