在Google APP Engine中遇到PHP会话问题

时间:2013-10-20 11:40:58

标签: php google-app-engine session app.yaml

我有三个档案......

1st是index.php

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cyber Boy Test App</title>
</head>
<body>
Hello 
<br/> This is Login System Test 
<br/>
<form method="post"  action="logincheck.php">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" name="submit" />
</form> 
</body>
</html>

第二个是logincheck.php

<?php
session_start();
$finaluser=$_POST['username'];
if($_SESSION['auth']=="yes")
{
    header('Location: name.php');   
}
else
{
    $connection=mysql_connect('localhost','root','')or die("Could not Connect to Database ");
    $db=mysql_select_db('test', $connection) or die(" Check the Database wrong database entered ");
    $sql="SELECT name from users WHERE username='$finaluser'";
    $result=mysql_query($sql) or die("Coudl not Execute the Query");
    $num=mysql_num_rows($result);
    $result=mysql_query($sql) or die("Coudl not Execute the Query2");
    $row=mysql_fetch_array($result);
    if($num==1)
    {
        echo "Login SuccesFull";
        $_SESSION['auth']="yes";
        $_SESSION['name']=$row['name'];
        echo '<a href="name.php">To Check the Name of the User Click Here';
    }
    else
    {
        echo "Login Failed";
    }
}
?>

第三个文件是name.php

<?php
echo $_SESSION['name'];
?>

当我提交表单时,它会将我带到logincheck.php页面,当我点击该链接时,我会看到name.php页面。 问题是,名称没有打印出来。 我很了解PHP,但我是Google App Engine的新手...... 我的app.yaml看起来像这样

application: testcboy
version: 1
runtime: php
api_version: 1
threadsafe: yes

handlers:

- url: /(.*)\.php
  script: \1.php

- url: /.*
  script: index.php

1 个答案:

答案 0 :(得分:2)

您需要在使用会话变量的所有PHP页面(例如顶部)上调用 session_start()

尽管其名称session_start()不仅仅是启动一个会话,但它还会恢复任何现有会话(如果它已经存在)(参见http://php.net/manual/en/function.session-start.php)。