douqiang6448 2017-11-01 01:43
浏览 58

PHP不会从登录表单重定向

I am making an html login page which will submit a form to a php page to check to see if user details lie in an established username access database. If the username and password correspond to a row in the database, the php redirects to an mainpage (mainpage.html), otherwise it redirects back to the login page (LOGINPAGE.html).

The if function I have used to achieve this in my php script is as follows:

if(odbc_fetch_row($DetailCheckExec)) //If username corresponds with password
    header('Location: mainpage.html');
    else 
        header('Location: LOGINPAGE.html');

The problem is, the php doesn't seem to redirect. Even if I simplify my code to simply redirect, nothing changes. i.e.

<?php
header("Location: LOGINPAGE.html");
exit;
?>

won't work either.

Any help is appreciated thank you.

  • 写回答

1条回答 默认 最新

  • dqy13020940 2017-11-01 01:59
    关注

    well i dont know the function "(odbc_fetch_row($DetailCheckExec)" but there's a step by step login that I made i hope it works

    if ((isset($_POST['user'])) and (isset($_POST['password'])))
    {//checks if the inputs in the form are empty
            //sets two variables with the value of the imputs
            $usuario = $_POST['user'];
            $clave = $_POST['password'];
            //then selects the row where the values are equal in the database
            $consulta = "SELECT usuario, contrasena FROM `usuarios` 
                            WHERE usuario = '$usuario' and contrasena = '$clave'";
    
            $resultados=mysqli_query($con,$consulta);
    
            while(($fila=mysqli_fetch_array($resultados))){
                    $vpeso = $fila['peso'];
                    $vestatura = $fila['estatura'];
                    $vusuario = $fila['usuario'];
                    }
    
            if(($resultados) AND ((isset($vusuario)) and ($vusuario <> '') )){
                //starts session
                session_start();
    
                //stablishes the user in the session
                $_SESSION['usuario'] = $usuario;
    
    
              //if the user doesn't exist it will bring to signup.php for example
              }else{
              header("Location: signup.php");
            }
    
    }
    

    well I hope it works, sorry for not changing the variable names haha

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀