0

When a person logs in, it directs them to the index.php band lets them checkout on my checkout page. When i change where i am directing them when they click login it doesnt work, then when they go to check out it keeps asking them to login. Anyone know where i may be going wrong?

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 </head>  
 <body>  
 <div id="main">
 <?php
 include "base.php"; 
 if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Email']))
 {
      ?>

     <h1>Member Area</h1>
        <p>Thanks for logging in! Your email address is: <b><?=$_SESSION['Email']?><b> 

     <ul>
          <li><a href="logout.php">Logout.</a></li>
     </ul>

      <?php
  }
  elseif(!empty($_POST['email']) && !empty($_POST['password']))
 {
     $email = mysqli_real_escape_string($_SESSION['base'], $_POST['email']);
     $password = md5(mysqli_real_escape_string($_SESSION['base'], $_POST['password']));

     $checklogin = mysqli_query($_SESSION['base'], "SELECT * FROM Users WHERE Email =   '".$email."' AND Password = '".$password."'");

     if(mysqli_num_rows($checklogin) == 1)
     {
        $row = mysqli_fetch_array($checklogin);
            $email = $row['Email'];

         $_SESSION['Email'] = $email;
         $_SESSION['LoggedIn'] = 1;

     }
     else
      {
         echo "<h1>Error</h1>";
         echo "<p>Sorry, your account could not be found. Please <a href=\"index.php\">click here to try again</a>.</p>";
     }
 }
 else
 {     
    ?>

    <h1>Member Login</h1>

    <p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>

     <form method="post" action="index.php" name="loginform" id="loginform">
     <fieldset>
    <label for="email">Email:</label><input type="text" name="email" id="email" />   <br />
        <label for="password">Password:</label><input type="password" name="password"     id="password" /><br />
        <input type="submit" name="login" id="login" value="Login" />
         </fieldset>
         </form>

    <?php
 }
 ?>
 </div>
 </body>
 </html>

And here is the base.php

 <?php
 session_start();

 $dbhost = "localhost"; // this will ususally be 'localhost', but can sometimes differ
 $dbname = "Abandoned"; // the name of the database that you are going to use for this project
 $dbuser = "root"; // the username that you created, or were given, to access your database
 $dbpass = ""; // the password that you created, or were given, to access your database
 $base = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); if (!$base){
            echo "<p>server connection error:
 mysqli_connect_error()</p>";
 }
 $_SESSION['base'] = $base; //database connection status transfer;
 ?>
4

2 回答 2

1

要使用基于 cookie 的会话,必须在向浏览器输出任何内容之前调用 session_start()。参考: http: //php.net/manual/en/function.session-start.php

要解决此问题,您可以移至 include "base.php"; 第一行 html 之前

于 2013-03-15T19:52:05.190 回答
0

改变:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 </head>  
 <body>  
 <div id="main">
 <?php
 include "base.php"; 

<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 </head>  
 <body>  
 <div id="main">

请记住,我假设 session_start() 在您的 base.php 文件中。如果不是,它可能应该是:) session_start() 需要在任何输出/标题之前运行。没有它,您的会话将无法正常工作。

于 2013-03-15T19:39:54.033 回答