我试图按照 youtube chanel 上的教程进行操作
当我遇到一些问题时。第一个是他在教程 #5 中的注销代码由于更改而不再起作用
if(session_is_registered()
我想我已经用
if( isset($_SESSION[$username])){
但是现在我收到一条错误消息,上面写着“注意:未定义的变量:在第 2 行登录 C:\xampp\htdocs\membership\index.php”
当我检查索引的第 2 行时,它显示我首先包含 global.php
<?php include_once('scripts/global.php');
if($logged==1){
header("Location:home.php");
exit();
}
?>
所以然后我检查 global.php 有 $logged=1 所以它应该被定义......除非我错过了什么。我真的很想在这里学习更多,所以在解释什么是错误的以及为什么......谢谢你的帮助。
<?php
session_start();
include_once('scripts/connect.php');
//checking if the sessions are set
if(isset($_SESSION['username'])){
$session_username=$_SESSION['username'];
$session_pass=$_SESSION['pass'];
$session_id=$_SESSION['id'];
//checking the member data
$query=mysql_query("SELECT * FROM members WHERE
id='id' AND password='pass' LIMIT 1")or die("Could not check member");
$count_count=mysql_num_rows($query);
if(count_count>0){
//logged in stuff here
$logged=1;
}else{
header('Location:logout.php');
exit();
}
}elseif(isset($_COOKIE['id_cookie'])){
$session_id=$_COOKIE['id_cookie'];
$session_pass=$_COOKIE['pass_cookie'];
//checking the member data
$query=mysql_query("SELECT * FROM members WHERE
id='$session_id' AND password='$session_pass' LIMIT 1")or die("Could not check member");
$count_count=mysql_num_rows($query);
if(count_count>0){
while($row=mysql_fetch_array($query)){
$session_username=$row['username'];
}
//create sessions
$_SESSION['username']=$session_username;
$_SESSION['id']=$session_id;
$_SESSION['pass']=$session_pass;
//logged in stuff here
$logged=1;
}else{
header('Location:logout.php');
exit();
}
}
?>