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条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类