【问题标题】:how to redirect wrong entered url如何重定向错误输入的url
【发布时间】:2013-11-27 02:55:58
【问题描述】:

我当前的 url 是 http://domain.com/example.php/link=eg 但如果有人使用 url 并将 url 设置为 http://domain.com/example.php/abcdefgh97654 - 任何东西,我的所有功能都来自该页面的所有链接都将变为无效。

我尝试在我的 php 文件中的所有链接之前使用<?=HTTP_SERVER;?>,但由于我的网站有用户注册和登录,当用户登录并单击任何菜单(来自 php 脚本的链接)时。它在 index.php 页面上抛出。但是,如果用户再次登录,它会完美运行。简而言之,用户需要登录两次才能完美运行。

  1. 基本上我想要两个解决方案一个我想重定向 www 点 domain dot com/example dot php/abcdefgh97654 - 任何东西(错误的 url 页面)到错误页面(我已经在 htaccess 中完成了此操作)但没有 适用于上述类型。
  2. 列表项

并且想解决两次登录问题。

如果有人对此有解决方案,将不胜感激。

【问题讨论】:

  • 你在使用某种框架吗?你在使用前端控制器模式吗?您可以添加一些您正在尝试做的示例代码吗?

标签: php


【解决方案1】:

为此,您必须知道应该通过$_GET 变量将哪些值传递到您的页面。然后您可以为值和用户header(); 函数创建过滤器。 这是我的建议:

<?php
$var=$_GET['val']
//get expected length if you need.
if(strlen($var)>9 or strlen($var)) {
$redirect=true;
}
//if you know what you are expecting
$vals=array('val1', 'val2, 'val3');
if(!in_array($var, $vals)){
$redirect=true;
}
//continue or replace your filters in this manner and asign your value to $redirect

if($redirect==true) {
header("Location:url"); // do this before anything else is printed to the page or else it will say headers already sent.
}

?>

【讨论】:

    猜你喜欢
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 2012-01-01
    • 1970-01-01
    • 2011-10-11
    相关资源
    最近更新 更多