dongpou7275 2014-08-06 11:41
浏览 23

SESSION参数不会转移到其他页面

I have a login page which sets a _SESSION parameter of 'id' upon login. After logging in the user is redirected to the index.php page and at this point the session parameter is still set, I know this because I can print it with PHP. However, when navigating to the account.php page the parameter is lost and I am not sure why.

Most of the other questions asked on here regarding this are because of the session_start not being used but I have used this on the account.php page.

Any help in resolving this would be grateful.

The code for the account.php page is below:

<?php session_start(); ?>
<?php
$con=mysqli_connect("localhost","tkernick96","Tylerkernick1996","users");

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$id = $_SESSSION['id'];

$query = mysqli_query($con,"SELECT * FROM users WHERE id = $id");

$row = mysqli_fetch_array($query,MYSQLI_ASSOC);
    $firstname = $row ['firstname'];
    $lastname = $row ['lastname'];
    $email = $row ['email'];
    $age = $row ['age'];
    $nationality = $row ['nationality'];
    $language1 = $row ['language1'];
    $language2 = $row ['language2'];
    $language3 = $row ['language3'];
    $language4 = $row ['language4'];
    $language5 = $row ['language5'];

$form = "<div id='header'>
           <img src='logo.png' id='logo'>
           <div id='headerdiv'>
            <table id='login'>
              <tr>
                <td style='padding-right: 20px;'>
                  <h2 style='margin-top: 0px'>No account?</h2>
                  <h3 style='margin-top: 0px'><a href='signup.php'>Sign Up Now!</a></h3>
                </td>
                <td style='padding-left: 20px; border-left: 1px solid #838383'>
                  <h3>Login:</h3>
                  <form method='post' action='login.php'>
                    <input id='logininput' type='email' name='email' placeholder='Email'>
                    <br>
                    <input id='logininput' type='password' name='password' placeholder='Password'>
                    <input type='submit' name='login' value='Login'>
                  </form>
                  <p id='p1'><a href='forgotdetails.php'>Forgotten Details?</a></p>
                </td>
              </tr>
            </table>
          </div>
        </div>";

$account = "<div id='header'>
            <img src='logo.png' id='logo'>
            <div id='headerdiv'>
              <table id='accounttable'>
                <tr>
                  <td id='account'>
                    <p id='p2'><a href='account.php'>My Account</a></p>
                    <p id='p2'><a href='account/companions.php'>My Companions</a></p>
                    <p id='p2'><a href='account/messages.php'>Messages&#40;".$messages."&#41;</a></p>
                    <p id='p2'><a href='logout.php'>Sign Out</a></p>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          <table id='profiletable'>
            <tr>
              <td id='profiletabletd1' rowspan='2'>
                <img src='images/avatar.png' id='profileimage'>
              </td
              <td id='profiletabletd1'><p id='profilename'>".$firstname." ".$lastname.", ".$age."</p></td>
            </tr>
            <tr>
              <td id='profiletabletd3'><p id='profileinfo'>Nationality: <b>".$nationality."</b> &nbsp&nbsp&nbsp Languages Spoken: <b>".$language1." ".$language2." ".$language3." ".$language4." ".$language5."</b></p></td>
            </tr>
          </table>
          ";


if ($id == "") {
$output = $form;
}

else {
$output = $account;
}

mysqli_close($con);
?>

index.php:

<?php session_start(); ?>
<?php
$con=mysqli_connect("localhost","tkernick96","Tylerkernick1996","users");

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$id = $_SESSION['id'];

$form = "<table id='login'>
        <tr>
        <td style='padding-right: 20px;'>
          <h2 style='margin-top: 0px'>No account?</h2>
          <h3 style='margin-top: 0px'><a href='signup.php'>Sign Up Now!</a></h3>
        </td>
        <td style='padding-left: 20px; border-left: 1px solid #838383'>
          <h3>Login:</h3>
          <form method='post' action='login.php'>
            <input id='logininput' type='email' name='email' placeholder='Email'>
            <br>
            <input id='logininput' type='password' name='password'  placeholder='Password'>
            <input type='submit' name='login' value='Login'>
          </form>
       <p id='p1'><a href='forgotdetails.php'>Forgotten Details?</a></p>
        </td>
        </tr>
        </table>";


$account = "<table id='accounttable'>
            <tr>
            <td id='account'>
              <p id='p2'><a href='account.php'>My Account</a></p>
              <p id='p2'><a href='account/companions.php'>My Companions</a></p>
              <p id='p2'><a href='account/messages.php'>Messages&#40;$messages&#41; </a></p>
              <p id='p2'><a href='logout.php'>Sign Out</a></p>
            </td>
            </tr>
            </table>";


if ($id == "") {
$output = $form;
}

else {
$output = $account;
}

mysqli_close($con);
?>
  • 写回答

2条回答 默认 最新

  • dpziir0079 2014-08-06 11:48
    关注

    it should be $_SESSION not $_SESSSION!

    you should see a warning with the right error reporting level, e.g.

    error_reporting(E_ALL);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭