is it possible to use a php includes if statement?

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

is it possible to use a php includes if statement?

Postby Esstee » Thu Jun 02, 2005 12:31 am

I want to know something, on my site I will be using php includes function.

Now there will be times when the included files may not be available and
I was wondering if there was any kind of condition I could use to prosent
a temporary .txt saying the data is unavailable instead of the includes error?
User avatar
Esstee
 
Posts: 320
Joined: Thu Nov 25, 2004 4:13 pm
Location: Deep in some project

Postby Psykosys » Thu Jun 02, 2005 1:55 am

You'll want something like:
Code: Select all
if (file_exists($profile)) {
   include $profile;
} else {
   echo "That profile does not exist or is currently unavailable";
}

Where you have set the variable "$profile" to the path/filename of the appropriate content file.
Psykosys
 
Posts: 252
Joined: Tue Apr 15, 2003 10:37 pm
Location: Ithaca, NY

Postby Esstee » Thu Jun 02, 2005 3:52 am

many thanks Psykosys
User avatar
Esstee
 
Posts: 320
Joined: Thu Nov 25, 2004 4:13 pm
Location: Deep in some project

Postby Esstee » Fri Jun 24, 2005 5:26 pm

I finally got around to trying this but I noticed this is perl.
I want to use it in a php page. any ideas how I could get the equivalent
code in php?
I went deeper into the belly of Coranto and look! I found maginot.
User avatar
Esstee
 
Posts: 320
Joined: Thu Nov 25, 2004 4:13 pm
Location: Deep in some project

Postby Psykosys » Sat Jun 25, 2005 3:51 pm

No, it's PHP (does look pretty similar to Perl though, when you're looking at a short code snippet like this) and should work at its basic purpose. But it only checks for file existence, maybe you're trying to use it to check for a locked file/one open for writing?
Psykosys
 
Posts: 252
Joined: Tue Apr 15, 2003 10:37 pm
Location: Ithaca, NY

Postby Esstee » Sat Jun 25, 2005 6:23 pm

I found this which worked beautifully.

Code: Select all
$includefile="http://www.mysite.com/index.txt";
$handle = fopen($includefile, "r", 1);
if ($handle) {
    fclose($handle);
   ob_start();
   require("http://www.mysite.com/index.txt");
   $info = ob_get_contents();
   ob_end_clean();
} else {

   ob_start();
   require("/home/www/public/web/errors/nofile.txt");
   $info = ob_get_contents();
   ob_end_clean();
}
I went deeper into the belly of Coranto and look! I found maginot.
User avatar
Esstee
 
Posts: 320
Joined: Thu Nov 25, 2004 4:13 pm
Location: Deep in some project

Postby InSAnE NiNjA » Sun Jun 26, 2005 9:50 am

Esstee wrote:I found this which worked beautifully.

Code: Select all
$includefile="http://www.mysite.com/index.txt";
$handle = fopen($includefile, "r", 1);
if ($handle) {
    fclose($handle);
   ob_start();
   require("http://www.mysite.com/index.txt");
   $info = ob_get_contents();
   ob_end_clean();
} else {

   ob_start();
   require("/home/www/public/web/errors/nofile.txt");
   $info = ob_get_contents();
   ob_end_clean();
}


holy crap, your actually using that?

and even above that.. you are actually having it look at the site through the outside of the server???

you do realize that the code psychosys wrote does the exact same thing and IS php code, right?
and it doesnt make the server cry for mercy
..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Postby Esstee » Sun Jun 26, 2005 12:06 pm

lol

Yes, I'm using it I wondered if anyone would notice the calls in this script.
this is placed in my "phpincludes_start" template in my vBulletin style.
and yes I am pulling data from a remote location for ver specific reasons. :)

I would not place many of these in my style but so far the load is acceptable.

you do realize that the code psychosys wrote does the exact same thing and IS php code, right?
and it doesnt make the server cry for mercy


the code psychosys wrote works for local file checking but not remote
furthermore I can only declare php include functions through my vBulletin
phpinclude_start template its a php security restriction that vBulletin implements.

I have tried several styles of php code to accomplish what I have above so
far this is the only piece that works.
I went deeper into the belly of Coranto and look! I found maginot.
User avatar
Esstee
 
Posts: 320
Joined: Thu Nov 25, 2004 4:13 pm
Location: Deep in some project

Postby InSAnE NiNjA » Sun Jun 26, 2005 7:12 pm

..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Postby Esstee » Sun Jun 26, 2005 7:53 pm

I don't quite see how this will improve my current situation.
I went deeper into the belly of Coranto and look! I found maginot.
User avatar
Esstee
 
Posts: 320
Joined: Thu Nov 25, 2004 4:13 pm
Location: Deep in some project


Return to Customization

Who is online

Users browsing this forum: No registered users and 1 guest

cron