是否可以通过使用PHP将用户重定向到不同的页面?
假设用户转到www.example.com/page.php,我想将其重定向到www.example.com/index.php,那么在不使用元刷新的情况下,我如何做到这一点?有可能吗?
这甚至可以保护我的页面免受未授权用户的攻击。
是否可以通过使用PHP将用户重定向到不同的页面?
假设用户转到www.example.com/page.php,我想将其重定向到www.example.com/index.php,那么在不使用元刷新的情况下,我如何做到这一点?有可能吗?
这甚至可以保护我的页面免受未授权用户的攻击。
当前回答
是的,可以使用PHP。我们将重定向到另一个页面。
尝试以下代码:
<?php
header("Location:./"); // Redirect to index file
header("Location:index.php"); // Redirect to index file
header("Location:example.php");
?>
其他回答
header("Location: https://www.example.com/redirect.php");
直接重定向到此链接https://www.example.com/redirect.php
$redirect = "https://www.example.com/redirect.php";
header("Location: $redirect");
首先获取$redirect值,然后重定向到[value],如:https://www.example.com/redirect.php
您可以使用会话变量控制对页面的访问并授权有效用户:
<?php
session_start();
if (!isset( $_SESSION["valid_user"]))
{
header("location:../");
exit();
}
// Page goes here
?>
http://php.net/manual/en/reserved.variables.session.php.
最近,我受到了网络攻击,并决定,我需要了解试图访问管理面板或web应用程序的保留部分的用户。
因此,我在文本文件中添加了IP地址和用户会话的日志访问,因为我不想打扰我的数据库。
是的,您可以使用header()函数,
header("Location: http://www.yourwebsite.com/user.php"); /* Redirect browser */
exit();
最好的做法是在header()函数之后立即调用exit()函数,以避免执行以下代码。
根据文档,在发送任何实际输出之前,必须调用header()。
我们可以通过两种方式实现:
当用户启动时https://bskud.com/PINCODE/BIHAR/index.php然后重定向到https://bskud.com/PINCODE/BIHAR.php通过以下PHP代码<?php文件header(“位置:https://bskud.com/PINCODE/BIHAR.php");出口?>将上述代码保存在https://bskud.com/PINCODE/BIHAR/index.php如果任何条件为真,则重定向到另一页:<?php文件$myVar=“bskud”;如果($myVar==“bskud”){?><script>window.location.href=“https://bskud.com“;</script><?php文件}其他{echo“<b>再次检查网站名称</b>”;}?>
您可以尝试使用
header('Location:'.$your_url)
有关更多信息,请参阅php官方文档