|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
So I'm making a hotlink prevention script, which verifies if the
requestor should be able to see the image, or not, and does one of the following operations depending: if(USERISVALID) { // header("Content-Type: image/jpeg"); // include $_SERVER['DOCUMENT_ROOT'].'/images/directory/hats1.jpg'; header("Content-Type: ".$array[$id][0]); include $_SERVER['DOCUMENT_ROOT'].'/gallery/'.$gal.'/'.$array[$id] [1]; exit; } else { header("Content-Type: image/png"); include $_SERVER['DOCUMENT_ROOT']."/template/imageFail.png"; exit; } The imageFail.png file which I made in Photoshop works perfectly, but when I try any other image (png's or jpg's) that I got off the web, it fails (just prints the url, as if the image was corrupted - which it's not). I'm still experimenting, trying to determine exactly what kind of images work and don't, but I'm wondering if anyone else has run into this problem, or have any solutions? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Hi,
Try readfile instead of include. You can also set error_reporting(E_ALL) to see if you have any notices. On Feb 27, 6:14 pm, MichaelD <dimo...@gmail.com> wrote: > So I'm making a hotlink prevention script, which verifies if the > requestor should be able to see the image, or not, and does one of the > following operations depending: > > if(USERISVALID) > { > // header("Content-Type: image/jpeg"); > // include $_SERVER['DOCUMENT_ROOT'].'/images/directory/hats1.jpg'; > header("Content-Type: ".$array[$id][0]); > include $_SERVER['DOCUMENT_ROOT'].'/gallery/'.$gal.'/'.$array[$id] > [1]; > exit;} > > else > { > header("Content-Type: image/png"); > include $_SERVER['DOCUMENT_ROOT']."/template/imageFail.png"; > exit; > > } > > The imageFail.png file which I made in Photoshop works perfectly, but > when I try any other image (png's or jpg's) that I got off the web, it > fails (just prints the url, as if the image was corrupted - which it's > not). I'm still experimenting, trying to determine exactly what kind > of images work and don't, but I'm wondering if anyone else has run > into this problem, or have any solutions? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
One thing to check, when you output a png or jpg, the Content-Type
should always match. On Feb 27, 6:14 pm, MichaelD <dimo...@gmail.com> wrote: > So I'm making a hotlink prevention script, which verifies if the > requestor should be able to see the image, or not, and does one of the > following operations depending: > > if(USERISVALID) > { > // header("Content-Type: image/jpeg"); > // include $_SERVER['DOCUMENT_ROOT'].'/images/directory/hats1.jpg'; > header("Content-Type: ".$array[$id][0]); > include $_SERVER['DOCUMENT_ROOT'].'/gallery/'.$gal.'/'.$array[$id] > [1]; > exit;} > > else > { > header("Content-Type: image/png"); > include $_SERVER['DOCUMENT_ROOT']."/template/imageFail.png"; > exit; > > } > > The imageFail.png file which I made in Photoshop works perfectly, but > when I try any other image (png's or jpg's) that I got off the web, it > fails (just prints the url, as if the image was corrupted - which it's > not). I'm still experimenting, trying to determine exactly what kind > of images work and don't, but I'm wondering if anyone else has run > into this problem, or have any solutions? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Feb 27, 4:28 pm, petersprc <peters...@gmail.com> wrote:
> Hi, > > Try readfile instead of include. > > You can also set error_reporting(E_ALL) to see if you have any > notices. > Yeah, I ended up using file_get_contents() which seems to work perfectly. Thanks for the ! |
|
![]() |
| Outils de la discussion | |
|
|