How to make include this file or include that file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
caitanya
Forum Newbie
Posts: 9
Joined: Mon Jan 19, 2004 3:36 pm
Location: Switzerland

How to make include this file or include that file?

Post by caitanya »

Hi,

I have this code:

<? if(basename($_SERVER['PHP_SELF'])=="index.php?S=1&Folder=1")
include("modules/links.php");
else {
echo "this folder/category has 0 links";
}
?>

In the code above I would like to say, if I am on the first page (HOME has .../index.php?S=1&Folder=1) than the links.php file should be included, but on all other sites only the message should come. But somehow this code above is not working properly - it always shows the message (this folder/category...)

Thanks for help
Ananda
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Do the following:

Code: Select all

echo basename($_SERVER['PHP_SELF'];
And see what the output is. Do this match index.php?S=1&Folder=1 ??

Why not just try:

Code: Select all

if((isset($_GET['S'] AND $_GET['S']==5)) AND (isset($_GET['Folder']) AND $_GET['Folder']==1)){
//include file
}else{
//echo error
}
caitanya
Forum Newbie
Posts: 9
Joined: Mon Jan 19, 2004 3:36 pm
Location: Switzerland

Post by caitanya »

echo basename($_SERVER['PHP_SELF'];
if i add this to my php code i get an error???

where exacly do I have to add this code?

thanks
Ananda
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Opps sorry i missed the closing ) from the end.

Code: Select all

echo basename($_SERVER['PHP_SELF']);
caitanya
Forum Newbie
Posts: 9
Joined: Mon Jan 19, 2004 3:36 pm
Location: Switzerland

Post by caitanya »

thanks,

i get the index.php and not index.php?S=1&Folder=1

so now it is logical...

But how can I sort out the first page?

This code you send me:

if((isset($_GET['S'] AND $_GET['S']==5)) AND (isset($_GET['Folder']) AND $_GET['Folder']==1))
include("modules/links.php");
else
{
echo "this folder/category has 0 links";
}

it is also not working... any ideas?`
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Code: Select all

print_r($_SERVER);
Will print the content of the $_SERVER array which holds details about the current page loaded etc. Run that code and see which of the array items holds information about the query string - the ?S=1&Folder=1 part.
caitanya
Forum Newbie
Posts: 9
Joined: Mon Jan 19, 2004 3:36 pm
Location: Switzerland

Post by caitanya »

I get this:

[PATH_TRANSLATED] => /srv/www/htdocs/web1/html/index.php [PHP_SELF] => /index.php [argv] => Array ( [0] => S=1&Folder=1 ) [argc] => 1 )

sorry for beeing such a neophyte but i am still learning :-)

Thanks for the help
Ananda
Post Reply