duankeng9477 2015-10-11 13:39
浏览 72

我怎样才能获得源页面网址

Now i need to get source page url when i navigate any page under specific domain i tried this jquery code

$(document).ready(function() {
var referrer =  document.referrer;
});

but i get the previous url page but i want to get the main link that open my domain for example i searched about my website from google then i open my website from google then i navigate any page under my domain ..... i want to get in any page that i come from google ..by the way my website is PHP.... can i make some thing like that ?!

  • 写回答

1条回答 默认 最新

  • duanju8431 2015-10-11 14:33
    关注

    On the server side, you can use $_SERVER['HTTP_REFERER'] to get the referrer.

    Now when the user links (or submits) from one page to the next in your website, but you still want the website they originally came from instead of the page they just were on, you should remember the original referrer in some way, for instance by storing it in a session variable. Something like this:

    $ref = $_SERVER['HTTP_REFERER'];         // Get referrer
    if (!$ref.strpos($_SERVER['HTTP_HOST'])) // It's not from the same domain?
      $_SESSION['originalreferrer'] = $ref;  // Nope, store in session
    

    Then you will have $_SESSION['originalreferrer'] as the original referrer, as long as you include this code in each of your pages that may serve as a landing page from outside.

    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析