简体   繁体   中英

how to redirect user in php

this is my code:

<?php
    if(isset($_POST['sub']))
    {
        $sql=("insert into info_user(u_fname, u_lname, u_pass, u_number, u_email)values('".($_POST['fname'])."','".($_POST['lname'])."','".($_POST['pass'])."','".($_POST['phone'])."','".($_POST['email'])."')");
        mysql_query($sql, $link);
        echo
        "you are registered successfully"
        "<a href="?action=login">'Login'<a/>";
    }
?>

I have problem with this one : echo "'Login'" there is a php page which contain nothing but some includes and the page with codes above is included. now i want to redirect user to login page, but i don't want to mention a new link.

is there a way to do so?

$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php?action=login';
header("Location: http://$host$uri/$extra");

(Source: Manual )

Make sure there is no kind of output (neither php nor html) before you send the header.

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