登录完成后使用get重定向PHP

时间:2014-02-17 20:53:41

标签: php url login get

    $redirect=$_GET["r"];
if ( isset($_GET["r"]) ){
    header("location: http://" .$redirect);
} else {
    $redirect = "mickiewiki.nl/login/profile.php";
    header("location: http://" .$redirect);

这段代码不起作用?我希望它如果我去mickiewiki.nl/login/login.php?r=mickiewiki.nl/Doneer.php,当我登录时,我回到页面Doneer.php

当我登录时,无论是否添加我的r,我都会被发送到profile.php

 <?php
   //allow sessions to be passed so we can see if the user is logged in
   session_start();

   //connect to the database so we can check, edit, or insert data to our users table

   $database = mysql_select_db('***', $con) or die(mysql_error());

   //include out functions file giving us access to the protect() function made earlier
   include "login/functions.php";
   $selectedid = $_GET['id'];
   if(empty($selectedid)) {
        $selectedid = $_SESSION['uid'];
   }
   if(strcmp($_SESSION['uid'],"") == 0){
        header("location: login/login.php?r=mickiewiki.nl/Doneer.php");
   } else {
   ?>

2 个答案:

答案 0 :(得分:0)

但是,你必须对$ _GET [“r”]进行控制......以及为什么它不起作用?

答案 1 :(得分:0)

在您网站上的表单中,您未将r设置为GET。您有usernamepassword&amp;您的表单submit - GET没有任何内容。如果您使用表单提交r(我无法看到您的表单),那么您应该检查$_POST['r']而不是$_GET['r']

基本上,您需要为r变量添加隐藏字段,并将其与表单一起提交。

<form method="post" action="login.php">
<input type="hidden" name="r" value="<?php print $_GET['r']; ?>">

<p><label for="name">Username: </label>
    <input type="text" name="username" /></p>
<p><label for="pwd">Password: </label>
    <input type="password" name="password" /></p>
<p>
<input type="submit" id="submit" value="Login" name="submit" />
</form>