| | |||||
| ||||||||
| CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 950
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | [php] I am having htaccess, gd2, and header problems, please help. 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);
?> ????: NamePros.com http://www.namepros.com/code/267683-php-i-am-having-htaccess-gd2.html Why? How can I stop this from happening?
Last edited by bliss; 12-10-2006 at 09:35 PM.
|
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Mar 2006 Location: United Kingdom
Posts: 413
![]() ![]() ![]() | 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?
__________________ Linux Screenshots |
| |
| | THREAD STARTER #3 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 950
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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. |
| |
| | #4 (permalink) |
| NamePros Member Join Date: Dec 2006
Posts: 122
![]() | 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() ?>" /> ????: NamePros.com http://www.namepros.com/showthread.php?t=267683 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
__________________ Check out some Available Domains I posted. |
| |
| | #6 (permalink) |
| NamePros Regular Join Date: May 2005 Location: England
Posts: 390
![]() ![]() ![]() | Try using PHP Code:
__________________ -Beaver6813.com - Web Developer Extraordinaire! |
| |