NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page [php] I am having htaccess, gd2, and header problems, please help.

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.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 12-10-2006, 07:20 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
bliss's Avatar
Join Date: Dec 2005
Posts: 950
bliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to all
 



[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);
?>
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.
????: 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.
bliss is offline  
Old 12-12-2006, 10:59 AM   #2 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: United Kingdom
Posts: 413
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
 




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
lee101 is offline  
Old 12-12-2006, 04:26 PM THREAD STARTER               #3 (permalink)
NamePros Regular
 
bliss's Avatar
Join Date: Dec 2005
Posts: 950
bliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to all
 



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.
bliss is offline  
Old 12-22-2006, 11:24 AM   #4 (permalink)
NamePros Member
 
keesj's Avatar
Join Date: Dec 2006
Posts: 122
keesj is an unknown quantity at this point
 



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.
????: 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.
keesj is offline  
Old 12-22-2006, 04:23 PM THREAD STARTER               #5 (permalink)
NamePros Regular
 
bliss's Avatar
Join Date: Dec 2005
Posts: 950
bliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to allbliss is a name known to all
 



Can't cause the link to the file is going to be a static link and I need it to display dynamic images.
bliss is offline  
Old 12-29-2006, 11:40 AM   #6 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 390
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Try using
PHP Code:
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.
beaver6813 is offline  
Old 12-30-2006, 07:51 PM   #7 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 584
jerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to all
 



This shouldn't be in the CODE forum anyways - it should be in the parent forum.
jerometan is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 03:14 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger