duankong8998 2012-09-12 08:19
浏览 99
已采纳

php页面重定向到另一个

I have a php page which should be included in otherpage but no directly. Lets assume it as 1.php and the other page as 2.php

1.php

<?php
   if($_SERVER['REQUEST_URI'] == "/1.php"){
       header("Location:2.php");
   }
   else
   {
       //some code here
   }
?>

2.php

<?php
   include("1.php");
?>

this worked well on localhost/1.php and have been redirected to localhost/2.php but this had made a problem with localhost/1.php?somegetmethod=data I found that anyone can access this page by typing ?something=something at the end of 1.php url. How to change the code which can redirect all url which starts with localhost/1.php

  • 写回答

5条回答 默认 最新

  • dtkmejg127475 2012-09-12 08:22
    关注

    you could check if a substring is at a given position like this

    if(strpos($_SERVER['REQUEST_URI'], "/1.php") === 0) {
    

    this checks if the REQUEST_URI starts with /1.php (= is at position 0)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备