Unstoppable Domains โ€” Expired Auctions

[Php] I am having htaccess, gd2, and header problems, please help.

SpaceshipSpaceship
Watch
I have a problem with a script doubling a count of the view's of a image when I display it. When I take ImagePNG($img); out of the script. The counter only counts it as one hit, but when I have imagepng($img) it shows it as two hits. I am very confused as to why it might be doing this. I do have headers in the file that make the file non-cache'd by the browser. Do you think it is counting it twice, because it is revalidating the image?


Here is the code.

Code:
<Files view>
	SetHandler application/x-httpd-php
</Files>

Code:
<?php
 session_start();
 
 include('connect_mysql.php');
 mysql_query("update bannerstats set exposures=exposures+1'");

 $bannerurl = "http://site.com/image.png";
 $imagestuff = @getimagesize($bannerurl);
 $imagetype = $imagestuff[2];
 if ( $imagetype == '2') { $img = imagecreatefromjpeg($bannerurl); }
 if ( $imagetype == '3') { $img = imagecreatefrompng($bannerurl); imageSaveAlpha($img, true); }

  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  header("Cache-Control: no-store, no-cache, must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0", false);
  header("Pragma: no-cache");
  header( "Content-type: image/png");
//exit;
  ImagePNG($img);
  ImageDestroy($img);
?>

If I uncomment exit then it will update exposures by one. If I show the image ,imagepng($img), and comment the exit it will update exposures by two.

Why?

How can I stop this from happening?
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I'm no expert with the GD image library but won't using exit; quit the script, therefore stopping any code after it from being executed? What happens if you put exit; at the very end of the script?
 
0
•••
I am using a session work around, but it is not that the script is not exiting. It is that the browser is loading the script twice. So, exit will not work with it. I think it has something to do with the headers and how i have it revalidate the file instead of running it from the cache'd copy. Which I can't get around cause I need it to show a different banner each time.
 
0
•••
You can try a couple of things. Firstly, try removing must-revalidate from your header. If that doesn't work, add it again and do the following:

Remove the cache stuff in your script. And when displaying the file on a html page to the following:
Code:
<img src="script.php?<?php time() ?>" />

This way every request is unique and therefor the browser won't use a cached file.

Or you can increment your stats by .5 ;)

You can also get into headers and figure out what really is causing the problem:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
 
0
•••
Can't cause the link to the file is going to be a static link and I need it to display dynamic images.
 
0
•••
Try using
PHP:
ob_start();
at the beginning of your file above session_start(); that will buffer everything until its all finished executing. I used the same kinda things as you're trying to do on my site http://www.diggfile.com which ill be releasing the source for soon.
 
0
•••
This shouldn't be in the CODE forum anyways - it should be in the parent forum.
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Live Options
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back