Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get referring url

    can somebody please tell me how to get the referring url of a page using javascript and how to incorporate it to my php page. I'm not really familiar with javascript

    Any kind of help would be much appreciated. Thanks!

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why do you need the referrer?

    btw: you don't need JS to do this: PHP can get it, too.
    *keep it simple (TM)

  • #3
    New Coder
    Join Date
    Dec 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have to display a different image based on the referring url. I tried the php code for that but it doesn't work with pop up windows. I think it can only get the referring url if it is in the same window.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to be honest, I wouldn't even bother with this sorta thing. you can't always get the referrer because it's not always sent. having JS disabled, firewalls, proxies, are just a few of the barriers to this.

    anyway, to get the referrer using JS do this, alert(document.referrer);
    *keep it simple (TM)

  • #5
    New Coder
    Join Date
    Dec 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, thanks but if i use the php code will the referring url be sent always? or are there similar problems?

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sassy_monix
    but if i use the php code will the referring url be sent always? or are there similar problems?
    what do you think? client- or server-side scripts are effected just as much as each other here
    *keep it simple (TM)

  • #7
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You could always dump the referer into a session variable/cookie when the user first arrives. Therefore you will have the location they came from.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51
    You could always dump the referer into a session variable/cookie when the user first arrives. Therefore you will have the location they came from.
    doesn't get round my earlier point - that the referrer isn't always available for n reasons.
    *keep it simple (TM)

  • #9
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    doesn't get round my earlier point - that the referrer isn't always available for n reasons.

    Well if it available when the user fiist comes, then it is logged, if it is not, then a filler needs to be in it. It is not that hard, and can try to give the person an answer!

    My blog software grabs all of the referers with no problem. It is possible.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •