Jump to content

passing HTTP_REFERER to another file, from file I can't directly access.


Dragen

Recommended Posts

I'm trying to get the page referrer to a page. I know that HTTP_REFERER is unreliable, but for what I'm doing that doesn't matter.

 

The problem I've got is that the file I'm getting the referrer from is linked to from another file. Basically I have one file containing an image, which is actually a php file that collects certain data.

img_test.php:

<img src="http://localhost/counter/3/img.png" />

Then in the image php file I have:

<?php
if(isset($_SERVER['HTTP_REFERER'])){
return $_SERVER['HTTP_REFERER'];
}else{
return '';
}
?>

The problem is all I'm getting as the referrer is http://localhost/img_test.php. Which I can understand as it's the file linking to the image.

 

Is there some way I can pass on the pages referrer to the image file? I could use php to create a GET variable, but I don't have access to the img_test.php file, because it's for a freeware project that people can use themselves and it's also designed to be used in .html files so less technical minded people can use it..

 

Any help would be greatly appreciated!

Thanks

Link to comment
Share on other sites

yeah, just checked the javascript side of doing this and it seems that I may have to use that (although I haven't tested it yet). Which is a shame as some people disallow javascript so it's a lot less reliable than php.

 

If anyone can think of a way for me to work it with php I'd more more than grateful!

Link to comment
Share on other sites

There must be some way of passing it on. Or would it perhaps have to be done in javascript.. if that's possible.

 

Nope, the only way to do it would be to edit the img_test.php page, as that's the referring page, regardless of the technology used whether it be client or server side.

 

Regards

Huggie

Link to comment
Share on other sites

No i can't alter the content on image_test.php, apart from telling the user what to put as the url to the image. The problem is I'm wanting image to be output using html, not php as many of the users wont have php or wont understand it anyway, so there files will most likely be .html.

 

I'm talking about adding the javascript into the code which creates the image, which will probably give much the same result as using http_referer in that file, but thought it's worth a try.

Link to comment
Share on other sites

Is there some way I can pass on the pages referrer to the image file? I could use php to create a GET variable, but I don't have access to the img_test.php file, because it's for a freeware project that people can use themselves and it's also designed to be used in .html files so less technical minded people can use it..

 

Is this something you can show me so I have a better understanding of what you're trying to achive?

 

Regards

Huggie

Link to comment
Share on other sites

okay. What I'm creating is a freeware hit counter that collects info of visitors to add to the stats. So I'm trying to get the referrer, so clients can tell who is linking to them.

The client would put the following (or similar) code into their page on their own website:

<img src="http://counterstop.co.uk/counter/3/img.png" border="0" alt="counterstop" title="counterstop" />

Which using htacces re-directs to my counter.php file which creates the image. The part between 'counter/' and '/img.png' in the url is the GET variables, which I extract in my php file.

 

Then in my counter.php file I go through the process of creating and displaying the image depending on the clients preferences (set in a control panel).

Before I create the image I need to collect the data from the current viewer to the client's page. This is the problem. Because the only code I can use has to be done within the counter.php file, meaning that all I get as the referrer is the client's page, instead of the referrer to the client's page.

 

if you go to: http://test.gimppro.co.uk/link.html

you can see what I mean. click on the link and it should display the counter. But it should save the referrer as http://test.gimppro.co.uk/link.html, but it doesn't.

 

 

I hope that made some vague sense..

Link to comment
Share on other sites

yeah.. the thing is I've seen other hit counters do it: http://www.webstat.net/basic/demo.php

You can see on the link above that it tracks referers, and to implement the counter you simply put the imkage code into your web page:

<img src="http://www.webstat.net/basic/track/47247.png" alt="Website Counter" border="0" />

 

So somehow they're working around the problem.

Link to comment
Share on other sites

Well if the refer is in your server, you can always do a pretty neat trick i found

on each page create a 2 sessions

$secret = rand();

$_SESSINON[$secret] = $page_name;

 

Then when you get to the next page you can return this name for your use, or insert an input type of

<input type="hidden" name="refer_<?php echo $secret;?>" value="<?php $page_name;?>" />

 

Then on the next page return this input (by finding it out with string test) and then compare if that session value exsit and is valid.  This will stop any cURL() because they can't set a session on your server, and even if they make a random number and a valid page name it wll never valid aganist the true session.

Link to comment
Share on other sites

thanks! I think I've found the lucky line ;)

one of the first bits of code in the javascript was this:

sc_referer=""+parent.document.referrer;

So I guess it's getting the 'parent' referrer, instead of the page holding the image. I know this has moved from php to javascript now though...

 

You'd think that php would have a similar function to the javascript 'parent.document', type thing, but I guess because it's server side that may be impossible.

Link to comment
Share on other sites

hi.

I've been trying the parent.document.referrer, but have found that cookies aren't being set for some reason. If I run the image directly: http://localhost/counter/3/W900/img.png, then it sets the cookie and works as expected, but if I'm simple linking the image from another file:

<img src="http://localhost/counter/3/img.png" border="0" alt="counterstop" title="counterstop" />

Then it seems to refuse to set a cookie for it. I know it's going through the javascript, because it reloads the image with the phpsessid which is done in javascript, but it just wont set cookies. I even tried using an alert, but that does nothing.

I'm going to post in the javascript section as well, but any idea why the javascript inside my php image file wont set, even though it's reading the javascript in the file?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.