网站的PHP登录和注销

网站的PHP登录和注销,php,Php,我正在看有关制作博客、登录和注销的教程 在登录和注销系统后,我得到了一些错误 从这个文件中的那些行 header.php <?php ob_start();?> <?php error_reporting(E_ALL); ini_set('display_errors', 1); include "include/config.php"; global $tf_handle; define("uid",$_COOKIE['uid']); define("login",$_C

我正在看有关制作博客、登录和注销的教程

在登录和注销系统后,我得到了一些错误

从这个文件中的那些行

header.php

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

include "include/config.php";
global $tf_handle;
define("uid",$_COOKIE['uid']);

define("login",$_COOKIE['login']);

$QuerySelectU = mysqli_query($tf_handle,"SELECT * FROM user WHERE u_id ='".uid."'");
$FetchObjectU = mysqli_fetch_object($QuerySelectU);
#========================[USER]========================#
define("u_id",$FetchObjectU->u_id); // different because of cookies and Db
define("uname",$FetchObjectU->u_name);
define("uemail",$FetchObjectU->u_email);
#========================[USER]========================#
?>
部分

index.php

<?php include"files/header.php";?>
<?php
global $tf_handle;

if(isset($_POST['login']))
{
    $u_name  = strip_tags($_POST['u_name']);    
    $u_pass  = md5($_POST['u_pass']);   
    if(empty($u_name) or empty($u_pass))
    {
        echo"
            <div class='error'>Please Fill the form</div><br />
            ";      
    }
    else
    {
        $sqlquery = mysqli_query($tf_handle,"SELECT * FROM user WHERE u_name = '".$u_name."' AND u_pass = '".$u_pass."'");
        if(mysqli_num_rows($sqlquery) > 0)
        {
            $fetchLquery = mysqli_fetch_object($sqlquery);
            $uid = $fetchLquery->u_id;
            $uname = $fetchLquery->u_name;
            $upass = $fetchLquery->u_pass;

            if($uname != $u_name AND $upass != $u_pass )
            {
                //AND $upass != $u_pass
                echo"
                <div class='error'>wrong information</div><br />
                ";  
            }
            else
            {

                setcookie("uid",$uid,time()+60*60*24);

                setcookie("login",1,time()+60*60*24);

                echo"
                <div class='error'>you be redirected to home page</div><br />
                ";
                header("Refresh: 5; url=index.php");

            }
        }
        else
        {
            echo"
                <div class='error'>Wrong Information</div><br />
                ";              
        }
    }
}
当我尝试打开index.php时

我犯了一些错误

注意:第8行的/var/www/html/Blog/files/header.php中未定义的索引:uid

注意:未定义索引:登录第13行的/var/www/html/Blog/files/header.php

注意:试图在第18行的/var/www/html/Blog/files/header.php中获取非对象的属性

注意:试图在第19行的/var/www/html/Blog/files/header.php中获取非对象的属性

注意:试图在第20行的/var/www/html/Blog/files/header.php中获取非对象的属性

我在退出系统后出现了这些错误

Logout.php

<?php include"files/header.php";?>
<?php



if(login == 1)
{
    setcookie("uid","",time()+60*60*24);

    setcookie("login","",time()+60*60*24);  
    echo"
    <div class='error'>Done </div><br />
    ";
    header("Refresh: 5; url=index.php");
}
else
{
    echo"
    <div class='error'>Wrong Page </div><br />
    ";  
}   
?>  
<?php include"files/block.php";?>
<?php include"files/footer.php";?>

您在登录后设置了cookie,因此在登录之前,您没有提供cookie值。但是在你的index.php中,define是尝试访问一个未设置的cookie值,这就是为什么它会向你显示错误,并且cookie在你登录之前没有设置,因此消息会显示出来

我不知道你看过哪些教程,但它们不是最好的。最好看看网络上有成百上千的教程,老实说,其中95%是完全无用的。找另一个。我试过了,但有人告诉我他们忘了上传css文件或类似的东西:/当我读到评论时,我看到3也说了忘了的文件..你看了教程吗。。但无论如何,我想知道原因和如何解决它:好的,我会搜索,但我需要知道他如何没有任何错误,只有我!?我需要一些帮助来修复此问题将cookie uid插入您的查询是一个非常糟糕的主意,您被SQL注入攻击。您知道我应该更改代码吗@微笑,这将出现在另一个问题中……你在问为什么你在这个问题中会出现这些错误hmmmm:D:D:D如果我提出另一个问题,你会告诉我如何解决这个问题??或者你不知道?为什么他输入了相同的代码却没有得到任何错误:D!!!!!我不保证,但至少其他人可以看一看……并尝试在你的帖子中清楚地陈述你的问题……按照SO指南正确地提问,这样其他人在阅读你的问题时就会少一些冲突。。