doushang3352 2010-06-08 18:56
浏览 38
已采纳

我如何编写条件语句来检查访问者是否来自特定站点?

What I have in mind is this... We are going to have people come from a particular site during a acquisition campaign and was wondering how I could conditionalize a certain section of my site to display a thank you message instead of the sign up form as they would have had the opportunity to fill this out before coming to my landing page.

I have seen solutions like: $referal = mysql_real_escape_string($_SERVER['HTTP_REFERER']);

I would like to know if this is the best way to get this to work???

->>> okay this is what i think might work. The third party website that is referring people to our landing page once the form on that site has been filled out can push into the record a hidden input value of "www.sample.com" or whatever... then I can have something check the for that particular value and fire off the conidtional.

Does that even sound right?

  • 写回答

3条回答 默认 最新

  • douyun8901 2010-06-08 19:01
    关注

    $_SERVER['HTTP_REFERER'] is the most reliable information you'll get about where your visitor came from. And it's not at all reliable. Some browsers may be configured to not send that header at all, and anybody can send misinformation, claiming they came from http://ultra-secure.top-secret.government.gov/ if they feel so inclined.

    With that caution in mind, it sounds like perfect reliability isn't a consideration here, and you're just hoping to save some time for visitors with a correct HTTP_REFERER set.

    In that case, comparing the beginning portion of that value to the www.example.com address where you expect visitors to originate with pre-filled-out signup information, would be the best way to go.

    Here's an example:

    $site = "http://www.sample.com/";
    if (!empty($_SERVER['HTTP_REFERER']) &&
            substr($_SERVER['HTTP_REFERER'], 0, strlen($site)) == $site) {
        //if execution reaches this point, user claims he came from www.sample.com
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥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 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算