我的 jquery 移动网站有问题。它的会话不工作。在服务器 register_global 在 php.ini 中关闭
有人请建议我如何在每个页面上获取会话数据。我在每个页面上都使用了 session_start。以下是我的php代码。
<?php
include("include/connect.php");
if(isset($_POST['submitted'])){
// $_POST['username'] and $_POST['password'] are the param names we sent in our click event
$email = $_POST['email'];
$password = md5($_POST['password']);
// Select eveything from the users table where username field == the username we posted and password field == the password we posted
$sql = "SELECT * FROM user WHERE email = '" . $email . "' AND password = '" . $password . "'";
$query = mysql_query($sql);
// If we find a match, create an array of data
if (mysql_num_rows($query) > 0)
{
$row = mysql_fetch_array($query);
$response = array(
'logged' => true,
'id' =>$row['id'],
'name' => $row['fullname'],
'email' => $row['email']
);
session_start();
$_SESSION['name']=$response['name'];
$_SESSION['email']=$response['email'];
$_SESSION['id']=$response['id'];
//redirect to homepage
header('Location: index.php');
}
else
{
// Else the username and/or password was invalid! Create an array, json_encode it and echo it out
$response = array(
'logged' => false,
'message' => 'Invalid Username and/or Password'
);
//echo json_encode($response);
$msg="<font color='red'> invalid username or password, try again</font>";
echo $msg;
}
}