简体   繁体   English

如何在php中重定向用户

[英]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. 我对此有疑问:echo“'Login'”有一个php页面,其中不包含任何内容,但包含一些内容,并且包含上述代码的页面。 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. 发送标头之前,请确保没有任何输出(php和html都没有)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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