php会话不在服务器上工作但在localhost中工作。为什么?

时间:2017-06-20 05:42:59

标签: php mysql

//这是我的登录页面。登录后,我去manpower.php页面选择一个产品。

<?php 

session_start();
include_once'db_connect.php';



if(isset($_POST['login']))
{

$username=mysqli_real_escape_string($mysqli,$_POST['username']);
$password=mysqli_real_escape_string($mysqli,$_POST['password']);

$_SESSION["username"]=$username;
$_SESSION["password"]=$password;

$select_user="SELECT * FROM admin WHERE username='$username' AND password='$password'";

$run_query=mysqli_query($mysqli,$select_user);

$row=mysqli_fetch_array( $run_query);

if ($row['username']==$username) {

         header('location:admin/index.php');           
}

 else
 { 

   $message = "you are not registerd !!";
    echo "<script type='text/javascript'>alert('$message');</script>";

  // 


 }

}



if(isset($_POST['userlogin']))
{

$username=mysqli_real_escape_string($mysqli,$_POST['username']);
$password=mysqli_real_escape_string($mysqli,$_POST['password']);

$_SESSION["username"]=$username;
$_SESSION["password"]=$password;

$select_user="SELECT * FROM users WHERE username='$username' AND password='$password'";

$run_query=mysqli_query($mysqli,$select_user);

$row=mysqli_fetch_array( $run_query);


if ($row['username']==$username) {

//           echo $_SESSION["username"];
         header('location:index.php');           
}

 else
 { 

   $message = "you are not registerd !!";
    echo "<script type='text/javascript'>alert('$message');</script>";

  // 


 }

}



?>

//这是人力页面。在localhost中,我可以选择任何产品,但是当我将其部署到服务器时。它首先显示错误消息但有效。

//警告:session_start():无法发送会话缓存限制器 - 已发送的标头(输出在/hermes/bosnacweb01/bosnacweb01ai/b1049/ipg.dreameducationbdcom/polyworld/Manpower.php:1开始)/ hermes / bosnacweb01第3行/bosnacweb01ai/b1049/ipg.dreameducationbdcom/polyworld/Manpower.php

你可以在这里看到错误

http://polyworldservice.com/Manpower.php

<?php

    session_start();
    include_once'db_connect.php';


     if(isset($_SESSION['username'])) {
  echo "Your session is running " . $_SESSION['userName'];
}





    $mysqli = new mysqli("localhost", "root", "", "travelagent");

    if(isset($_POST['status']))
    {

      if (!isset($_SESSION["username"]))

      {    

         $message = "please login!!";
        echo "<script type='text/javascript'>alert('$message');</script>";



        }

        else

        {    
                $id = mysqli_real_escape_string($mysqli, $_POST['id']);
                $username=$_SESSION["username"];




             $_SESSION['id']=$id;
            $sql = "UPDATE product SET status='1' WHERE id='$id' " ;

         if(mysqli_query($mysqli,$sql)==true){





               $message = "added to cart!! ";

        echo "<script type='text/javascript'>alert('$message');</script>";

             $sql="INSERT INTO cart (user_name, product_id) VALUES ('$username','$id')";

             $result=$mysqli->query($sql);



            session_destroy();

             }


    }
    }

    ?>


<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Polyworld Services</title>
        <meta name="Description" content="Polyworld">
        <meta name="viewport" content="width:device-width" initial-scale="1">
        <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">


    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    <script
      src="https://code.jquery.com/jquery-2.2.4.js"
      integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="
      crossorigin="anonymous"></script>

    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">


    <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- Custom CSS -->
    <link href="css/full-slider.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/style.css">


    </head>

    <body  data-spy="scroll" data-target="#my-navbar">

    <?php 

        include'header.php';

      ?>



    <h1 style="text-align:center;">Welcome to Manpower page</h1> 

    <div class="row" id="content">
    <?php 

    $result=$mysqli->query("SELECT * FROM product WHERE category_id='1' AND sub_category_id='1' AND status='0'" );

    while($row=$result->fetch_array())

    {                 
           ?>


    <div class="col-md-3">

          <ul> 










            <li>picture : <?php    echo "<img src='admin/".$row['image']. "' height='200' width='200'>";  ?> </li>
            <li>Name: <?php  echo $row['name'];           ?></li>

            <li>Description :<?php    echo $row['description'];        ?></li>
            <li ><a href="#">Details</a></li>
            <form action="" method="post">
            <input type="text" name="id" value="<?php echo $row['id']; ?>">





            <li><input type="submit" name="status" value="add to cart"></li></br>
            </form> 
          </ul>


          </div>





    <?php                 

    }

    ?>
    </div>                 


<?php  include'footer.php'; ?>

     <script type="text/javascript">


    </script>


    </script>

    <script type="text/javascript" src="js/custom.js">

    </script>

    <script src="js/jquery.js"></script>

        <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>




    </body>
    </html>

0 个答案:

没有答案