FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


image php sripting that made a image refreshed every loaded





phicha
good afternoon everyone here, Smile
i got a question, actually need a help,
how can i disabled image php sripting that made a image refreshed every loaded ?

i have image php script that make a picture turn to small size, but every time a browser browse that image, the browser still need to took a new image, so it took my bandwidth.

Code:
$filename=$_GET["id"];
list($width_orig, $height_orig) = getimagesize($filename);
$width = 80;
$height = 80;
$kena=false;
if ($width_orig>120||$height_orig>120||$kena==true)
{
   if(substr(strtolower($filename),-3)=="jpg"||substr(strtolower($filename),-3)=="peg")
   {
      header('Content-type: image/jpeg');
      if ($height_orig>=$width_orig){
         $width = $width_orig*($height/$height_orig);
         $height = $height_orig*($height/$height_orig);
      }else
      {
         $width = $width_orig*($width/$width_orig);
         $height = $height_orig*($width/$width_orig);
      }
      if ($width && ($width_orig < $height_orig)) {
         $width = ($height / $height_orig) * $width_orig;
      } else {
         $height = ($width / $width_orig) * $height_orig;
      }
      $image_p = imagecreatetruecolor($width, $height);
      $image = imagecreatefromjpeg($filename);
      imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
      imagejpeg($image_p, null, 100);
   }
   if(substr(strtolower($filename),-3)=="jpg"||substr(strtolower($filename),-3)=="peg")
   {
      header('Content-type: image/jpeg');
      readfile(getcwd()."/".$filename);
   }
}


i want to make that browser know the picture still same and take it from cache, not from my site again..

Thanks for read my request of help here ^^"
kv
can you post the html which is using the image? It may be just a wrong way or changing url which might be causing multiple downloads.

Also, note that it depends on browser settings. You can set browser to always fetch data from server though a cached version is available.
phicha
i wonder is it had a security hole also on these script ?
hexkid
phicha wrote:
i wonder is it had a security hole also on these script ?
I don't think so, but I wouldn't allow an user to go to, for example

http://yourserver.com/smallsize.php?id=http%3A%2F%2Fantwrp.gsfc.nasa.gov%2Fapod%2Fimage%2F0611%2Fmtransit06_cortner_big.jpg
phicha
hexkid wrote:
phicha wrote:
i wonder is it had a security hole also on these script ?
I don't think so, but I wouldn't allow an user to go to, for example

http://yourserver.com/smallsize.php?id=http%3A%2F%2Fantwrp.gsfc.nasa.gov%2Fapod%2Fimage%2F0611%2Fmtransit06_cortner_big.jpg


yes it can be done like that,
is there a way to prevent that thing ?
chris20
to check for something like you could use regular expressions, or even just a string check type thing like strpos or strstr

strpos("http://asdf.com","http"); // returns a number if it finds something, false if it doesnt

with regular expressions, you can use the preg_match(); function, just google that, and also regular expressions php for more info

hope that helps with the security problem
hexkid
phicha wrote:
yes it can be done like that,
is there a way to prevent that thing ?


Code:
$filename=$_GET["id"];
if (!is_file($filename)) {
  // $filename does not reference an existing file
  exit("Wrong id. Try again.<br>\n");
}
// ... your code
phicha
please look at this site at this My Site
and look at the Newest Member Gallery part,
there is 9 last picture gallery that refreshed every time the browser refresh.
why don't the browser took the picture from cache ?

thanks..
phicha
and i tested with change cache;s ssize more bigger than before also try to open site from other place, but it seem same,

it refreshed & took a time to wait until finish picture loading.
Related topics
[TUTOR] A Short Intro to GD
script of guestbook in PHP
Java tutorials
EDIT: document root
$10Fr -- name this font.
Selling Community ad space! DDS
Jamatus' Dynamic image store
A frihost newsletter DDS
Chemical Attacks - by US Forces // Impeach Bush
How to create a php files that contain a image ?
Image
.: User login systems for your site :. CHEAP AND EASY!
AJAX and PHP contact form
<?php session_start(); ?> on Every Page
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.