Jump to content

Getting URL of page using script embedded as img


rtadams89

Recommended Posts

I have no idea how to phrase this simply, so here is the long explanation. I wanted to track the number of people who view my ads posted on craigslist. Craigslist won't let you embed PHP, javascript, or any external files in the posts, except for images. SO here is what I did:

 

I created a file named "hit.php" on my server. In my craigslsit post, i include:

<img src="http://myserver.com/hit.php?id=1234">

 

When called, hit.php records the hit in a database and then uses a header(location) to redirect to a transparent gif file. The "id" parameter in the URL is the id of the post. This has to be hard coded into each craigslist post I make.

 

I would instead like to pull the ID from the post URL automatically. For example, in the post http://phoenix.craigslist.com/sys/1234.html the id would be "1234". Is there a way to do this when the hit.php script is being called from an "<img>" tag?

Link to comment
Share on other sites

All you would do(if I read this correctly..) would be:

 

send the entire url into the id variable, then break it apart to get the "1234". For example:, exploding all the "sys/" in the variable into, say $temp and then exploding the . in the $temp[1] variable into, say, $temp2. Then $temp2[0] would have the 1234. That's how I break them up anyways. there's probably an easier way, like with preg_replace.

Link to comment
Share on other sites

I'm not quite sure you understand how browsers put pages together. =P  The image tag won't send any referrer data because all the browser does it send a GET request to your server for the image (which in this case is a PHP page that sends image headers, so the browser doesn't know the difference).

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.