简体   繁体   中英

PHP Redirecting correct login to another HTML page?

I have a login page which links with a small PHP Database and when the username and password are correct I need it to redirect to 'Welcome.html'. I have tried the header and exit; but it doesn't seem to work?

if ($testhash == $hash) 
{
    header( "Location: Welcome.html" );
    //exit; (doesn't work either)
    //echo "login correct\n\n";
}   
else 
{

    echo "login incorrect\n\n";
}

Use url please

if ($testhash == $hash) 
{
    header( "Location: http://your-url/welcome.html" );
    exit;
}   
else 
{

    echo "login incorrect\n\n";
}
  1. you should make sure that there is no output (echo, print functions and so on are not alowed) before header function
  2. if you use Apache then ModPageSpeed(if active) might do some conflicts

You should use the header() function.

http://www.php.net/manual/en/function.header.php

The reason your header may not be working is that is has to be right at the top of your PHP file. You also need to use a full URL as the header parameter.

The header() function sends header data to the browser and needs to come before any <html> input.

For example:

<?php
     header( "Location: http://www.example.com/welcome.php" );
     exit;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM