Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在url中设置目标页面_Php_Html_Url - Fatal编程技术网

Php 在url中设置目标页面

Php 在url中设置目标页面,php,html,url,Php,Html,Url,我有一张表格。当用户单击表单上的链接时,我想将他重定向到登录页面,一旦他登录,他应该被引导回表单页面,而不是任何其他页面 如何实现此重定向。有没有办法设置url的目的地?您可以使用header()以重定向浏览器。下面是一个快速场景: <?php if (md5($_POST['password']) == $server_password) // You are hashing, right ;) { header('location:www.example.com'); } ?&

我有一张表格。当用户单击表单上的链接时,我想将他重定向到登录页面,一旦他登录,他应该被引导回表单页面,而不是任何其他页面

如何实现此重定向。有没有办法设置url的目的地?

您可以使用
header()以重定向浏览器。下面是一个快速场景:

<?php

if (md5($_POST['password']) == $server_password) // You are hashing, right ;)
{
  header('location:www.example.com');
}

?>

在重定向到登录页面的代码中,获取当前请求URL(使用$_SERVER['request_URI']),对其进行URL编码(使用适当命名的urlencode函数),并将其作为查询字符串变量附加到重定向到的URL中(比如returnurl)

然后,在登录页面中,检查returnurl是否在查询字符串中,如果在查询字符串中,则重定向到它

我对PHP不太了解,但这应该会让您找到正确的方向。

您有两个脚本:

使用登录表单编写脚本A:

    <form id="someId" action="login-action.php?redirect=<?php print(urlencode('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'])); ?>" method="post">

<?php

if(isset($_GET['redirect'])){

    header('location:'.urldecode($_GET['redirect']));
}