PHP:为什么我的会话变量没有设置在这里?

时间:2014-03-04 16:08:42

标签: php

我在localhost上测试了我的代码并且它工作正常,在我的实际服务器上,$ _SESSION ['regID']的值没有在Buttons.php中设置,但它在checklogin.php中设置这里的代码任何帮助都会非常感谢

checklogin.php

<?php

session_start();
ob_start();

?>
<?php

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM appusers WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

$sqlreg="SELECT * FROM appusers WHERE username='$myusername' ";
$resultreg=mysql_query($sqlreg);

// Mysql_num_row is counting table row
$countreg=mysql_num_rows($resultreg);

if($countreg==1) {
    echo "success";
    while($row = mysql_fetch_array($resultreg))
    {
        echo $row['username'] . " " . $row['regID'];
        echo "<br>";
        $_SESSION['regId'] = $row['regID'];
        echo "<br>";
        echo $_SESSION['regId'];

        header("location:http://mywebsite.com/project/Buttons.php");
    }
}
else {
     echo "Wrong Username or Password";
}
?>

Buttons.php

<?php 
session_start();

Print_r($_SESSION);

?>
<html>

<?php 

$regID=$_SESSION['regId'];
echo $regID; 

if(isset($_SESSION['regId']))
echo "success";
else
echo "failed";


?>
</html>

1 个答案:

答案 0 :(得分:0)

您是否收到任何PHP错误?
尝试将此添加到您的脚本

<?php
 error_reporting(E_ALL);
 ini_set('display_errors', 1);