Can't redirect from login page to home page

This question already has an answer here:

  • How to make a redirect in PHP? 27 answers

  • As long as you have not outputted anything to the browser, you can do a header redirect. This will achieve your aim.

    Change this:

    echo ("<center><a href='home.php'>Redirect</a></center>");
    $_SESSION['username'] = $username;
    

    To this:

    $_SESSION['username'] = $username;
    header("Location: /some-new-page.php");
    exit;
    

    Always exit; after a location redirect.

    Oh yeah, and CLEAN your inputs.. ..you are wide open to SQL Injection.

    $username = mysql_real_escape_string($_POST["username"]);
    $password = mysql_real_escape_string($_POST["password"]);
    

    Oh yeah .. and mysql_* is deprecated. Use mysqli_*


    use header("Location:home.php"); its best way to redirect page in php


    header("Location:whaeverpage.php");
    exit();
    

    Do it before sending any data to the browser or you will get a header allready sen error

    or by javascript :

    If($connected ==='yes'){//your connection statement
       ?>
           <script>window.location.replace("whatever_page");</script>
       <?
    }
    
    链接地址: http://www.djcxy.com/p/34720.html

    上一篇: 从一个页面重定向到另一个页面

    下一篇: 无法从登录页面重定向到主页面