Dynadot โ€” .com Registration $8.99

Getting Refferer with Javascript

Spaceship Spaceship
Watch

dre

Established Member
Impact
3
hey, does anyone know how to get the refferer with javascript then pass it on to a php script for that to write to a text file? i got the php bit sorted i just need the java script bit to place in my .html to pass the vars to my php script

Code:
<!--
  stats = "referrer=" + escape(window.document.referrer);
  stats += "agent=" + escape(navigator.userAgent);
  document.write('button.php' + stats +'">');
//-->
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
how about the server variable $_SERVER('http_referer')

That's the server variable for asp. I don't do php, but I'm pretty sure it's the same.


By the way, I have never gotten that varible to return anything in asp, but if your Jscript is working, you can submit it to a php file through a form on load. Just use something like:

HTML:
<body onLoad="myForm.submit()">
<form id="myForm" action="refered.php" method="POST">
<input type=hidden value=referrer>

I'm sure there's an easier way, but that's what popped into my head :)
 
0
•••
If the end result is PHP, why not get the referrer in PHP?

<?php
$ref= $_SERVER['HTTP_REFERER'];
?>

However, don't rely on it too much, since the referer is sent from teh client, it's not trustworthy.
 
0
•••
i dnt want to use straight php, because i of to put in .tpl files, so if i get the details then pass it to a remote php script that then writes to a txt file, that possible?
 
0
•••
What's wrong with your existing code (with a few mods)?

Code:
<!--
  stats = "?referrer=" + escape(window.document.referrer);
  stats += "&agent=" + escape(navigator.userAgent);
  document.write('button.php' + stats);
//-->

That should output "button.php?referrer=<referrer here>&agent=<agent here>" into the page where you have the script... no?
 
0
•••
that code i post doesnt work
 
0
•••
dre said:
if i get the details then pass it to a remote php script that then writes to a txt file, that possible?

Did you see the code I posted? Because, that's what it does.
 
0
•••
im not using a FORM!
 
0
•••
Why wouldn't you want to use a hidden form?
 
0
•••
eh... tired of playing hide-and-seek with help-seekers, constantly guessing what the problem could be because of lack of working info, like errors, results, source, desired operation, desired output, what you've tried on your own, etc...

Diagnosing software and server issues is often difficult work without being able to see or understand the whole picture. It's funny how people want to give you just a tiny, half worn, and barely recognizable peice of a puzzle and ask for someone to describe the completed picture to them. Then, when someone takes time out of their day to attempt to help, the seeker dares to get short with the helper... eh, tough sh*t, figure it out yerself.. I originally wondered why few people dive in to help in various forums, especially the programming one, and now I see that they probably just gave up on ungrateful requestors...

For future reference, here's a decent guide on how to ask a question:

How to ask questions the smart way

Particularly important would be the following sections:

Discuss your problem's symptoms, not your guesses

Discuss your problem's symtoms, in chronological order

Describe the goal, not the step

and

Courtesy never hurts, and sometimes helps

Good luck finding a solution,
Mike
 
Last edited:
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back