rtadams89 Posted June 22, 2008 Share Posted June 22, 2008 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? Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 22, 2008 Share Posted June 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
rtadams89 Posted June 22, 2008 Author Share Posted June 22, 2008 Yes. I should have been more clear. I don't know how to get the url of the page into a variable. I've tried using the http referer variable, but that is always empty. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 23, 2008 Share Posted June 23, 2008 Can't you just figure the url out once you submit an ad? You'd submit it, copy the url, then edit it to change the img tag's url and you should be fine. Quote Link to comment Share on other sites More sharing options...
rtadams89 Posted June 23, 2008 Author Share Posted June 23, 2008 That is what I am doing now. I was going to release this script for others to use, and I thought getting the post id and section automatically would make it more user friendly. Quote Link to comment Share on other sites More sharing options...
rtadams89 Posted June 23, 2008 Author Share Posted June 23, 2008 It appears that when embedded in a craigslist post using an <img> tag, the $_SERVER['HTTP_REFERER'] doesn't get set. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 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). Quote Link to comment Share on other sites More sharing options...
rtadams89 Posted June 23, 2008 Author Share Posted June 23, 2008 I'm wondering if there is anything I can use to get the URL of the page that is requesting the image. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 I don't *think* so, and if there is, I'd be interested. Other than passing the page in the URL of course. Quote Link to comment Share on other sites More sharing options...
rtadams89 Posted June 23, 2008 Author Share Posted June 23, 2008 It seems there has to be. I mean, it's making a request to the server. One which shows up in the logs, can be modified with mod rewrite, etc. I just don't know enough about PHP or web standards and protocols to figure it out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.