gpt4 book ai didi

php - if 语句和 session

转载 作者:行者123 更新时间:2023-11-29 04:43:53 25 4
gpt4 key购买 nike

无论用户是否登录,我都在尝试相应地更改菜单。它不断出现此错误:

注意: undefined variable :C:\xampp2\htdocs\JobBoard\menu.php 中第 3 行的 _SESSION菜单.php

<?php

$useremail = $_SESSION['login_user'];

if($useremail==NULL)
{
$loggedinout='<div id="menulogin"><a href="register.php">Register</a> | <a href="login.php">Login</a> &nbsp </div>';
}
else
$loggedinout='<div id="menulogin"><a href="logout.php">Logout</a> &nbsp </div>';

echo'
<link rel="stylesheet" type="text/css" href="stylesheets/menu.css" />
<div id="menucontainer">' . $loggedinout . '<div id="menulogo"><img src="images/logo.png" /></div>
<div id="searchmenu"></div>
'
?>

这是我开始 session 时的页面登录.php

<?php
include 'menu.php';
include 'db_connect.php';
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// email and password sent from Form
$myemail=addslashes($_POST['email']);
$mypassword=addslashes($_POST['password']);

$sql="SELECT userID FROM users WHERE email='$myemail' and password='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);


// If result matched $myemail and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myemail");
$_SESSION['login_user']=$myemail;

header("location: index2.php");
}
else
{
$error="location: test.php";
}
}
?>

我相信这对某些人来说是一件很容易的事情。请帮忙

最佳答案

您有 include 'menu.php'; before session_start()。 PHP 按顺序运行,所以当 include 发生时, session 还没有开始。

尝试将 session_start() 放在文件的最开头:

session_start();
include 'menu.php';
include 'db_connect.php';

关于php - if 语句和 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22824933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com