无法在php中访问会话变量

时间:2018-11-10 10:27:08

标签: php session

我正在尝试在第二页上使用会话变量$_SESSION['name'],即review.php。 但是在第二页上却没有任何帮助我如何在第二页上使用Session变量? 这是index.php

  <?php 
    session_start();
    $connect = mysqli_connect('localhost','root','root','review');
     if(isset($_POST['submit']))
     {
        $id = $_POST['id'];
        $_SESSION['name']  = $id;
     }



   ?>

        <!DOCTYPE html>
        <html>
        <head>
            <title>
                login
            </title>
            <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
        </head>
        <body>
            <form action="review.php">
                <input type="text" name="id" placeholder="id">
                <input type="password" name="password" placeholder="password">
            <input type="submit" name="submit" class="btn btn-success">
        </form>
        </body>
        </html>

这是review.php

<?php 

session_start();
$connect = mysqli_connect('localhost','root','root','review');
if(isset($_SESSION['name']))
{
    echo $_SESSION['name']; 
 }
 else{
    echo "nothing";
 }

?>

1 个答案:

答案 0 :(得分:0)

您有2个问题:

  1. 您将提交的表单发送到{ "edges": [ { "node": { "id": "121323", "slug": "path1", "information": { "propertyID": "property1" } } }, { "node": { "id": "332342", "slug": "path2", "information": { "propertyID": "property2" } } }, { "node": { "id": "123234", "slug": "path3", "information": { "propertyID": "property3" } } } ] } ,因此您应该阅读review.php中的表单数据
  2. 您未设置表单review.php。默认情况下,methodmethod,但是您读了GET变量。 (What is the default form HTTP method?

因此,您应按以下步骤更改$_POST

index.php