首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >标题或会话问题

问标题或会话问题
EN

Stack Overflow用户
提问于 2014-04-10 15:38:11
回答 1查看 69关注 0票数 0

看起来,在将处理表单张贴到它的头上,然后在重新加载时,源格式化中断,因为css div消失了,会话无法工作。

代码语言:javascript
复制
<?php session_start(); ?>
<html>  
    <head>
        <title>Webpage</title>
        <link rel="stylesheet" type="text/css" href="Style.css">
    </head>
    <body>      
        <Div align="center">
            <Formlad>
                <form action="loginprocess.php" method="post" target="_self">
                    Username: <input type="text" name="username" Value='' required><BR>
                    Password: <input type="password" name="pass" Value='' required><BR>
                    Submit: <input type="submit" value="Submit" required>
                </form>
            </Formlad>
        </Div>
        <div align="center">
            <Errorbox>
                <?php
                    echo ($_SESSION['Logindets']);                  
                ?>
            </Errorbox>
        </div>
    </body>
</html>

好的,数据被发布到处理页面,然后设置会话,一个标题将用户带回页面,并给出关于登录成功的消息。这是一份测试文件,hense是一次成功尝试的不合逻辑的重定向。

代码语言:javascript
复制
<html>
    <?php
        $tmpusername=$_POST["username"];
        $tmppassword=htmlspecialchars($_POST["pass"]);



        $con=mysqli_connect("localhost","usr","password","database") or die(mysql_error()); 
        $pnquery = "SELECT max(ID) AS ID from table" ;
        $result = mysqli_query($con,$pnquery);
        $IDtemp=(mysqli_fetch_array($result));
        $IDmax=$IDtemp['ID'];

        $IDc=1;
        While ($IDc<>($IDmax+1)){
            $pnquery = "SELECT Username from table Where ID ='$IDc'" ;
            $result = mysqli_query($con,$pnquery);
            $Usrtemp=(mysqli_fetch_array($result));
            if ($tmpusername==$Usrtemp['Username']){
                $nothiredu=1;
            }
            $IDc=$IDc+1;
        }

        $IDc=1;
        While ($IDc<>($IDmax+1)){
            $pnquery = "SELECT Password from table Where ID ='$IDc'" ;
            $result = mysqli_query($con,$pnquery);
            $Usrtemp=(mysqli_fetch_array($result));
            if ($tmppassword==$Usrtemp['Password']){
                $nothiredp=1;
            }
            $IDc=$IDc+1;
        }

        $IDc=1;
        While ($IDc<>($IDmax+1)){
            $pnquery = "SELECT Username from table Where ID ='$IDc'" ;
            $result = mysqli_query($con,$pnquery);
            $Usrtemp=(mysqli_fetch_array($result));
            if ($tmpusername==$Usrtemp['Username']){
                $hiredu=1;
            }
            $IDc=$IDc+1;
        }

        $IDc=1;
        While ($IDc<>($IDmax+1)){
            $pnquery = "SELECT Password from table Where ID ='$IDc'" ;
            $result = mysqli_query($con,$pnquery);
            $Usrtemp=(mysqli_fetch_array($result));
            if ($tmppassword==$Usrtemp['Password']){
                $hiredp=1;
            }
            $IDc=$IDc+1;
        }
        If (($nothiredu==1) and ($nothiredp==1)){
            $_SESSION['Logindets']='STUFfff.......';
            header("Location: http://localhost/Login.php");
            exit;
        }
        if (($hiredu==1) and ($hiredp==1)){

            $pnquery = "SELECT ID from table Where Username ='$tmpusername'" ;
            $result = mysqli_query($con,$pnquery);
            $IDtemp=(mysqli_fetch_array($result));
            $_SESSION['Logindets']='YOUR IN SON WHOOOP';
            $_SESSION['Loginsuc']=1;
            $_SESSION['LoginTime'] = time();
            $_SESSION['LoginID'] = $IDtemp['ID'];
            $_SESSION['LoginUsr'] = $tmpusername;
            header("Location: http://localhost/Login.php");
            // put this ------ if($_SESSION['loginTime'] + 1000 < time()){ ------ on each page where the login is being used. 
        }
        if (($hiredu==1) and ($hiredp==0)){
            //Username is correct incorrect password
            $_SESSION['Logindets']='Your Username or Password is incorrect';
            header("Location: http://localhost/Login.php");
            exit;
        }

        if ($hiredu==0){
            $_SESSION['Logindets']='Your Username or Password is incorrect';
            header("Location: http://localhost/Login.php"); 
        } 

    ?>

</html>

所以我的问题不再是我的表单有什么问题,而是我的php有什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-10 16:10:32

使用两个标头总是会出现一些错误,尝试在上面的代码中使用die()代替exit()

或

使用元标签

代码语言:javascript
复制
 <META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://localhost/Login.php">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22992613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档