Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having a little problem with require()

Status
Not open for further replies.

TheAtomic

Technical User
Oct 18, 2004
9
GB
Code:
<?php
if($page == ""){$page = "main";} ;
if($name == ""){$name = "blank";} ;

if($gallery == "true"){require("pics/".$name."_index.php");}
else {require("$page.php");}

?>

If i set gallery to 'true' and name to 'hols' (which the page its linking to exists) it just shows a blank page...

index.php?gallery=true&name=hols

Im sure it something to do with

require("pics/".$name."_index.php");

but Im not sure what...
 
this
require("pics/".$name."_index.php");

will evaluate to this
pics/hols_index.php

are you sure this file exists relative to where you're calling it from? i.e. {calling_dir}/pics/hols_index.php



-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
do you have register global ON? turn it off! and use $_GET

for:

Code:
index.php?gallery=true&name=hols
==>

if($_GET['name'] == ""){$name = "blank";} ;

if($$_GET['gallery'] == "true"){require("pics/".$name."_index.php");}

Chacal, Inc.[wavey]
 
narrowed the problem right down now.

Code:
{require("pics/".$name."_index.php");}

If i change it to:

Code:
{require("".$name."_index.php");}

and create hols_index.php in the same folder, it gets the file correctly, the problem is getting it to include it from a sub directory...
 
as an aside, you can replace
{require("".$name."_index.php");}

with
{require("$name_index.php");}

and it will work the same

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
jemminger said:
as an aside, you can replace
{require("".$name."_index.php");}

with
{require("$name_index.php");}

and it will work the same
That doesn't work on my system, and I'm not suprised, as "$name_index.php" is ambiguous. That ambiguity is going to trip up the parser and will make the script less readable.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
How odd...

Code:
{require("./pics/".$name."_index.php");}

Works fine :)
 
true - the leading underscore does it. this should work though:

{require("${name}_index.php");}




-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
That's still less readable. What's wrong with:

{require($name . '_index.php');}

You have an explicit concatentation of a variable's value and a string constant. No weird attempts to abuse variable variables, no implicit concatenation.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
personal preference. it's easier to write that way than it is to explicitly concatenate. i find it just as legible.

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top