这是login.php,它的标题位置是index.php,我想在索引页面上存储会话ID,但没有显示任何内容
<?php
@extract($_POST);
include("config.php");
$sql="select password,name,us.id as uid from us left join tblblo on (tblblo.maker=us.id) where name='$websitename' and password=md5('$password')";
$result=$db->query($sql);
if($count=mysql_num_rows($result)>0)
{
$row=mysql_fetch_assoc($result);
$_SESSION['name']=$row['name'];
$_SESSION['id']=$row['uid'];
header("location:http://".$_SESSION['name'].".domain.com");
}
else
{
//$_SESSION['sess_msg']="Invalid Web Name or Password!Try Again.";
//header("location:https://domain.com/login.php");
//exit;
}
?>
我想在索引页面上存储会话ID但是没有显示任何内容
答案 0 :(得分:1)
1)在输出任何其他内容之前,在代码的最开头写session_start();
总是好的。
<?php
session_start();
@extract($_POST);
include("config.php");
2)您已将已弃用的 mysql
API与object_oriented
个混合使用。
改变这个:
if($count=mysql_num_rows($result)>0)
{
$row=mysql_fetch_assoc($result);
$_SESSION['name']=$row['name'];
$_SESSION['id']=$row['uid'];
对此:
$count = $result->num_rows;
if($count > 0)
{
$row = $result->fetch_assoc());
$_SESSION['name']=$row['name'];
$_SESSION['id']=$row['uid'];
3) 这是login.php,其标题位置是index.php,我想在索引页面上存储会话ID,但没有显示任何内容
我认为你的意思是在 index.php 上使用/ echo会话值而不是 store ?
index.php上的(在login.php上成功存储会话之后):
<?php
echo $_SESSION['name'];
echo $_SESSION['id'];
?>