dqysi86208 2013-09-19 21:52
浏览 74
已采纳

使用$ _SERVER ['HTTP_REFERER']和GET变量

I'm using PHP and I'd like to create an if statement that does something if the user came to the current page from the home page. So far, I've been using this code:

if(!in_array($_SERVER['HTTP_REFERER'], $validHomes){
//do something}

The array $validHomes contains a couple different variations of index.php (without .php, without www.)

This has been working fine but now I'd like the home page to have a GET variable sometimes which will have different values: www.example.com/index?var=5. $_SERVER['HTTP_REFERER'] treats URLs with GET variables that have different values as different from each other so I'm wondering if anyone has a suggestion for how to get around this? How can I trigger the if statement for a wide range of index URLs that contain GET variables with different values?

Thanks a lot for any help.

  • 写回答

2条回答 默认 最新

  • dongqiongjiong4740 2013-09-19 21:53
    关注

    It would be better to add a GET parameter from your home page links and check for that parameter instead. This would be far simpler and more reliable.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度