-2

我一直试图让会话从我的索引页面转移到我的主页,该页面有我的登录表单,但一直回到索引页面。我不知道出了什么问题,我检查 session_start() 是否在两个页面上。非常需要帮助,任何帮助将不胜感激。

index.php 脚本:

`<?php
 error_reporting(E_ALL ^ E_NOTICE);
 session_start();

 if(isset($_COOKIE['loginMemPro'])) 
 {
 include_once("Connections/first.php");

  $memEmail = $_COOKIE['loginMemPro']['memEmail'];  
  $password = $_COOKIE['loginMemPro']['log_password'];

    $query = "SELECT email, password FROM pro_members WHERE email = '$memEmail' AND   
     password = '$password'";
    $result = mysql_query($query);
    if(mysql_num_rows($result)) 
{
$_SESSION['loggedin'] = 1;  
$_SESSION['loginMem'] = $memEmail;
header('Location: http://www.pro.com/home.php');
exit();
}
    }
   ?>
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <link href="/image/x-con.png" rel="icon" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    <form id="userlogin_form" name="userlogin_form" action="login_process.php" 
     method="post">
     <table width="100%">
      <tr>
      <td width="20%">&nbsp;</td>
      <td width="20%">&nbsp;</td>
      <td width="20%">
                    <span id="sprytextfield5">
          <span class="textfieldRequiredMsg">A email address is required.</span><span 
       class="textfieldInvalidFormatMsg">Invalid email address format.</span><br/>
       Email
          <input name="memEmail" type="text" id="memEmail" value="" size="30" />
          </span></td>
        <td width="20%">&nbsp;</td>
        <td width="20%">&nbsp;</td>
         </tr>
          <tr>
        <td>&nbsp;</td>
         <td width="20%">&nbsp;</td>
         <td>
          <span id="sprylog_password">
          <span class="passwordRequiredMsg">A password is required.</span><br/>
          Password
            <input name="log_password" type="password" id="log_password" value="" 
          size="30" />
          </span></td>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
       </tr>
       <tr>
       <td>&nbsp;</td>
        <td width="10%">&nbsp;</td>
        <td>               
        <label for="memberMe">
          <input name="memberMe" type="checkbox" id="memberMe" value="setcookie" />
          Remember Me</label>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
       <tr>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right"><input id="submit" type="submit" name="login" value="login" />  
      </td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
       </tr>
       <tr>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
       <td align="right">
        <a id="forgotpw_link_id" class="forgotpw_link" href="">forgot password?</a>
        </td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
        </tr>
       </table>
       </body>
       </html>`

home.php 脚本:

   `<?php
     $path = $_SERVER['DOCUMENT_ROOT'];
        $path .= "/login_auth.php";
      include_once($path);?>
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml">
      <?php
     $path = $_SERVER['DOCUMENT_ROOT'];
         $path .= "/CSS/home_style.css";
     include_once($path);?>


      <body class="thrColLiq" onload="MM_preloadImages">

     <div id="header">
       <?php
     $path = $_SERVER['DOCUMENT_ROOT'];
     $path .= "/header.php";
     include_once($path);?>
      <!-- end #mainContent -->
        </div>
      <div id="container">
      <div id="sidebar1">
       <?php
      $path = $_SERVER['DOCUMENT_ROOT'];
      $path .= "/leftside_bar.php";
     include_once($path);?>
     </div>  
    <div id="sidebar2">
    <?php
     $path = $_SERVER['DOCUMENT_ROOT'];
    $path .= "/rightside_bar.php";
     include_once($path);?>
     </div>

     <!-- This clearing element should immediately follow the #mainContent div in order 
     to force the #container div to contain all child floats -->
<div id="mainContent">
  <!-- end #mainContent -->
      <?php
       $path = $_SERVER['DOCUMENT_ROOT'];
        $path .= "/menu.php";
       include_once($path);?>
      < /div>
   <div id="mainContent2">
         <?php
       $path = $_SERVER['DOCUMENT_ROOT'];
    $path .= "/home_script.php";
     include_once($path);?>

  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp; </p>
  </div>
  <div id="mainContent3">
  <!-- end #mainContent -->
      <?php
       $path = $_SERVER['DOCUMENT_ROOT'];
       $path .= "/footer.php";
      include_once($path);?>
      </div>
  <br class="clearfloat" />
      <!-- end #container -->
       </div>
     </body>
     </html>
      `

登录 auth.php 脚本:

    `<?php
     error_reporting(E_ALL ^ E_NOTICE);
     session_start();

     if(!isset($_SESSION['loggedin'])) {        
      header('Location: http://www.pro.com/index.php?error=1');
     exit();                    
     }
     ?>
     `

login_process.php 脚本:

     `<?php
       error_reporting(E_ALL ^ E_NOTICE);
        session_start();            
       include_once("Connections/first.php");
      $memEmail = mysql_real_escape_string($_POST['memEmail']); 
      $password = mysql_real_escape_string($_POST['log_password']);


       $time = time();                  
      $check = $_POST['memberMe'];              

      $query = "SELECT email, password FROM pro_members WHERE email = '$memEmail' AND    
       password = '$password'";
      $result = mysql_query($query);
      if(mysql_num_rows($result)) {     
  $_SESSION['loggedin'] = 1;    
  $_SESSION['loginMem'] = $memEmail;
  if($check) {      
  setcookie("loginMemPro[memEmail]", $memEmail, $time + 3600);    
  setcookie("loginMemPro[log_password]", $password, $time + 3600);  
  }

      header('Location: http://www.pro.com/home.php');
      exit(); 
     }
     else
    {
     header('Location: http://www.pro.com/index.php?error=1');
     exit();
     }
     ?>`
4

2 回答 2

0

您的 index.php 没有session_start();但是您需要检查您的错误日志并告诉我们是否有任何错误。您的错误报告只会在某些情况下显示错误,而不是涵盖所有情况,因为它不是您 php 的第一行脚本。

看这里:

$_SESSION['loggedin'] = 1;  
$_SESSION['loginMem'] = $memEmail;

因为没有 session_start(); 在这两个之前,无法创建这些..

索引不包括login auth.php或者login_process.php我没有看到 index.php 上 session_start 的位置?

旁注:Don't use mysql_*!!

于 2013-01-20T05:43:58.473 回答
0

您需要使用 session_start(); 在顶部的每一页上。只有在该会话之后才会起作用。

如果仍然没有创建会话,请检查 php.ini 中的会话设置

对于您的会话,您必须在 php.ini 文件中设置或重置以下参数

Define path to save sessions
session.save_path = "C:\php\sessiondata\"

Whether to use cookies.
session.use_cookies = 1 

To Initialize session on request startup.
Set session.auto_start = 1

Name of the session (used as cookie name).
session.name = PHPSESSID

Define Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

;The path for which the cookie is valid.
session.cookie_path = /

The domain for which the cookie is valid.
session.cookie_domain =

 Handler used to serialize data. php is the standard serializer of PHP.
session.serialize_handler = php

还有一些设置可用于修改您的会话。有关详细信息,请在每个页面脚本中手动参考 php.ini 支持:调用 session_start() 函数。

于 2013-01-20T07:07:43.357 回答