Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 09-07-2009, 02:57 PM   #1
Voodoo
♥ ♦ ♣ ♠
 
Voodoo's Avatar
 
Industry Role:
Join Date: Sep 2002
Location: Porn Valley, CA
Posts: 10,590
PHP Checking if URL/File Exists... Return True/False

Code:
<?php if(file_exists("http://www.site.com/images/$id/misc6.jpg")){ DO THIS }?>
For some reason this doesn't seem to work. When I remove this check, the image shows up under { DO THIS }, however, the check doesn't seem to be returning a TRUE on this statement. What's the best way to return TRUE/FALSE for a remote image if it exists?

EDIT: Note... $id is assigned above this statement.
__________________

"I'm selflessly supporting the common good, but only coincidentally looking out for No.1."
Voodoo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-07-2009, 03:09 PM   #2
Voodoo
♥ ♦ ♣ ♠
 
Voodoo's Avatar
 
Industry Role:
Join Date: Sep 2002
Location: Porn Valley, CA
Posts: 10,590
Bumpity Bump
__________________

"I'm selflessly supporting the common good, but only coincidentally looking out for No.1."
Voodoo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-07-2009, 03:09 PM   #3
Varius
Confirmed User
 
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
file_exists doesn't support checks on remote files.

why not just try with fopen ?
__________________
Skype variuscr - Email varius AT gmail
Varius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-07-2009, 03:50 PM   #4
Dirty D
Confirmed User
 
Dirty D's Avatar
 
Join Date: May 2002
Location: Paying Webmasters Millions Since 1999
Posts: 4,044
also make sure

allow_url_fopen is enabled

(Dirty D has chicks in the pool on Labor Day, why am I commenting on someone else's code?)
Dirty D is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-07-2009, 04:25 PM   #5
mikeyddddd
Viva la vulva!
 
mikeyddddd's Avatar
 
Join Date: Mar 2003
Location: you can't please everyone, so you got to please yourself
Posts: 16,557
Quote:
Originally Posted by Dirty D View Post
(Dirty D has chicks in the pool on Labor Day, why am I commenting on someone else's code?)
Shrinkage


mikeyddddd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 04:31 AM   #6
calmlikeabomb
Confirmed User
 
calmlikeabomb's Avatar
 
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
The most secure way to accomplish what you need is using cURL.

Many will argue that enabling URL wrappers is a potential security risk within PHP. Just google and you'll find many articles. This is why that option is turned off by default in the configuration file.
__________________
subarus.
calmlikeabomb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 05:02 AM   #7
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
if the file is an image every time... you can use getimagesize >> http://us2.php.net/getimagesize

Code:
Example #3 getimagesize (URL)
<?php
$size = getimagesize("http://www.example.com/gifs/logo.gif");

// if the file name has space in it, encode it properly
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");

?>
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 05:04 AM   #8
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Quote:
Originally Posted by calmlikeabomb View Post
The most secure way to accomplish what you need is using cURL.

Many will argue that enabling URL wrappers is a potential security risk within PHP. Just google and you'll find many articles. This is why that option is turned off by default in the configuration file.
allow_url_fopen isn't really a big risk... allow_url_include is.
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 06:10 AM   #9
calmlikeabomb
Confirmed User
 
calmlikeabomb's Avatar
 
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
allow_url_include doesn't work unless allow_url_fopen is enabled, buddy.
__________________
subarus.
calmlikeabomb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 07:22 AM   #10
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Quote:
Originally Posted by calmlikeabomb View Post
allow_url_include doesn't work unless allow_url_fopen is enabled, buddy.
They have separate flags... so it is possible to enable allow_url_fopen and turn off allow_url_include.
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 09:09 AM   #11
Davy
Confirmed User
 
Davy's Avatar
 
Industry Role:
Join Date: Apr 2006
Location: Germany
Posts: 4,323
__________________
---
ICQ 14-76-98 <-- I don't use this at all
Davy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 09:15 AM   #12
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
This is incredibly basic shit. The following is a top-down-no-classes-used example, using cURL, as suggested above. Note the lack of RETURNTRANSFER as we're only checking the status code.

Code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.site.com/blah/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch,CURLOPT_VERBOSE, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$pageData=curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

switch ($statusCode) {
  case 404:
    filemissing()...
    break;
  case 401:
    authreq();
    break;
  default:
   whatev();
}
Quote:
Originally Posted by nation-x View Post
if the file is an image every time... you can use getimagesize >> http://us2.php.net/getimagesize
Do not use getimagesize() as a boolean for validation - that is VERY unsafe.
__________________

Last edited by GrouchyAdmin; 09-08-2009 at 09:18 AM.. Reason: getinagesize() is bad for all living things
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 01:28 PM   #13
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Quote:
Originally Posted by GrouchyAdmin View Post
Do not use getimagesize() as a boolean for validation - that is VERY unsafe.
Please provide an example to prove your assertion... how exactly is this unsafe?

This is how I would use it.

Code:
$file_url = "http://www.site.com/images/{$id}/misc6.jpg";
$file_exists = is_array($file_url);

Last edited by nation-x; 09-08-2009 at 01:32 PM..
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 01:32 PM   #14
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by nation-x View Post
Please provide an example to prove your assertion... how exactly is this unsafe?[/code]
Generally, lazily coded image hosting scripts. The easiest way to abuse this I've actually seen in the wild. It starts with a valid GIF header, and has a PHP script as the payload. WIthout giving away too many details, file naming conventions and autonegotiation can cause you bigtime issues.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 01:38 PM   #15
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
should have been:
Code:
$file_url = "http://www.site.com/images/{$id}/misc6.jpg";
$file_exists = is_array(getimagesize($file_url));
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 01:50 PM   #16
MichaelP
Registered User
 
Industry Role:
Join Date: Aug 2003
Location: QWEBEC Corporate Office
Posts: 7,124
$yourfile = "full/path/to/your/file.php-jpg-gif-whatever" ;
IF (file_exists($yourfile)) {
print "Your File Does Existst" ; // TRUE
} ELSE {
print "Your file Doesn't exists" ; // FALSE
}

Last edited by MichaelP; 09-08-2009 at 01:52 PM..
MichaelP is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 01:54 PM   #17
Tom_PM
Porn Meister
 
Industry Role:
Join Date: Feb 2005
Posts: 16,443
I ran into this issue long ago, but I think I solved it by realising that both domains I was working with were on the same server, doh!

Good luck.
__________________
43-922-863 Shut up and play your guitar.
Tom_PM is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 02:15 PM   #18
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Quote:
Originally Posted by MichaelP View Post
$yourfile = "full/path/to/your/file.php-jpg-gif-whatever" ;
IF (file_exists($yourfile)) {
print "Your File Does Existst" ; // TRUE
} ELSE {
print "Your file Doesn't exists" ; // FALSE
}
Not gonna work captain.
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 02:16 PM   #19
ProG
Confirmed User
 
Join Date: Apr 2009
Posts: 1,319
Quote:
Originally Posted by Killswitch View Post
Not gonna work captain.
I don't even think he read the thread.
__________________
History will be kind to me for I intend to write it.
ProG is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 02:32 PM   #20
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Jeeesus peoples. This is a hack of a slightly-better-than-my-above for just checking for the files' existence, based upon code at PHP.net; I figured this thread should die a horrible death, so here ya go.

Code:
function http_file_exists($url=FALSE) {
  // Bad URL, bail.
  if (!(@parse_url($url))) return FALSE;
  // No cURL, bail.
  if (!(function_exists('curl_init'))) return FALSE;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_NOBODY, 1);
  curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  return (curl_exec($ch) !== FALSE) ? TRUE : FALSE;
}
Here's even a (shitty) working example:

Code:
$urltest = array ("http://www.google.com/logo.gif", "http://www.google.com/intl/en_ALL/images/logo.gif");

foreach ($urltest as $url) {
  echo http_file_exists($url) ? "$url exists.\n" : "$url is a 404.\n";
}
exit;
Code:
http://www.google.com/logo.gif is a 404.
http://www.google.com/intl/en_ALL/images/logo.gif exists.
Can this go away now pls?
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 02:54 PM   #21
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Quote:
Originally Posted by GrouchyAdmin View Post
Jeeesus peoples. Can this go away now pls?
buttsecks???!!! :D
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 02:57 PM   #22
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by nation-x View Post
buttsecks???!!! :D
I gave at the office.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:04 PM   #23
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Quote:
Originally Posted by GrouchyAdmin View Post
Jeeesus peoples. This is a hack of a slightly-better-than-my-above for just checking for the files' existence, based upon code at PHP.net; I figured this thread should die a horrible death, so here ya go.

Code:
function http_file_exists($url=FALSE) {
  // Bad URL, bail.
  if (!(@parse_url($url))) return FALSE;
  // No cURL, bail.
  if (!(function_exists('curl_init'))) return FALSE;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_NOBODY, 1);
  curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  return (curl_exec($ch) !== FALSE) ? TRUE : FALSE;
}
Here's even a (shitty) working example:

Code:
$urltest = array ("http://www.google.com/logo.gif", "http://www.google.com/intl/en_ALL/images/logo.gif");

foreach ($urltest as $url) {
  echo http_file_exists($url) ? "$url exists.\n" : "$url is a 404.\n";
}
exit;
Code:
http://www.google.com/logo.gif is a 404.
http://www.google.com/intl/en_ALL/images/logo.gif exists.
Can this go away now pls?
No, I refuse to let it! BUMMMPPP!!
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:09 PM   #24
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by Killswitch View Post
No, I refuse to let it! BUMMMPPP!!
I cutchoo mang. I cutchoo so bad you wish I no cutchoo.


...and I'm gonna keep using a banned imagehost until this damn thing goes away. S'there!
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:10 PM   #25
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Quote:
Originally Posted by GrouchyAdmin View Post
I cutchoo mang. I cutchoo so bad you wish I no cutchoo.


...and I'm gonna keep using a banned imagehost until this damn thing goes away. S'there!
I cut you back... I cut you deep, I cut you so deep, yo momma be like "WTF IS THAT!?!?".

Imageshack works on gfy.com, fail.
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:12 PM   #26
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by Killswitch View Post
Imageshack works on gfy.com, fail.
LOS GROUCHY KICK YOUR ASS
LOS GROUCHY KICK YOUR FACE
LOS GROUCHY http_file_exists() IN TO OUTER SPACE

Dammit. It used to be banned as far back as.. two weeks ago.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:13 PM   #27
munki
Do Fun Shit.
 
munki's Avatar
 
Industry Role:
Join Date: Dec 2004
Location: OC
Posts: 13,393
__________________

I have the simplest tastes. I am always satisfied with the best.” -Oscar Wilde
munki is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:28 PM   #28
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Quote:
Originally Posted by GrouchyAdmin View Post
LOS GROUCHY KICK YOUR ASS
LOS GROUCHY KICK YOUR FACE
LOS GROUCHY http_file_exists() IN TO OUTER SPACE

Dammit. It used to be banned as far back as.. two weeks ago.
LOS GROUCHY KICK ROCKS
LOS GROUCHY NO HURT
LOS GROUCHY http_file_exists() RETURN ERROR FOR SUCKAGE

Hmm, weird, that little smiley you posted from imageshack showed for me on gfy.com
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:30 PM   #29
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by Killswitch View Post
LOS GROUCHY KICK ROCKS
LOS GROUCHY NO HURT
LOS GROUCHY http_file_exists() RETURN ERROR FOR SUCKAGE

Hmm, weird, that little smiley you posted from imageshack showed for me on gfy.com
Yeah, well, you're Retox_Josh.

Feel that burn, motherbitch. Feel it!? Mmmyeah. That's the stuff.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:42 PM   #30
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
return (!file_get_contents('URL')?false:true);
Do I win ?
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:51 PM   #31
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Quote:
Originally Posted by GrouchyAdmin View Post
Yeah, well, you're Retox_Josh.

Feel that burn, motherbitch. Feel it!? Mmmyeah. That's the stuff.
Touché

You win this time my little pretty, but I will get you and your dog too!
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:52 PM   #32
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by quantum-x View Post
return (!file_get_contents('URL')?false:true);
Do I win ?
No. Michael P wins for 'not reading the fucking thread at all', but nice try.

Quote:
Originally Posted by Killswitch View Post
Touché

You win this time my little pretty, but I will get you and your dog too!
Surrender Grouchy, my ass.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 03:59 PM   #33
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
Quote:
Originally Posted by GrouchyAdmin View Post
No. Michael P wins for 'not reading the fucking thread at all', but nice try.



Surrender Grouchy, my ass.
Damnit .
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 04:02 PM   #34
munki
Do Fun Shit.
 
munki's Avatar
 
Industry Role:
Join Date: Dec 2004
Location: OC
Posts: 13,393
__________________

I have the simplest tastes. I am always satisfied with the best.” -Oscar Wilde
munki is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 04:04 PM   #35
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by quantum-x View Post
Damnit .
You do get a few points for ternary abuse, though.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-08-2009, 04:30 PM   #36
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
Quote:
Originally Posted by GrouchyAdmin View Post
You do get a few points for ternary abuse, though.
If you cram it aaaalllll onto one line, if the script ever breaks, at least you know the line to debug
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.