Forum Moderators: coopster

Message Too Old, No Replies

php syntax

         

th1chsn

4:16 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



I was hoping someone would be able to help me with some syntax that I'm trying to come up with.

I want to create a condition that displays certain code on certain pages of the site. The logic would be something like this:

if page <> main.php?downloads.php then
show this code
else
show nothing
end if

or should I just declare a variable on the page where I don't want the code to show and then use the logic to reference that variable?

$page = 0 //put this on the page where I don't want it to show
$page = 1 //put this on all other pages
if page = 1 then
show this code
else
show nothing

Can someone help me with the syntax?

TIA.

d40sithui

5:34 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



hi,
i thikn i know what you're trying to do. You might want to familiarize yourself with the $_REQUEST and $_GET variables.

//////// index.php //////////
<?
$page = $_REQUEST['page']; //gets variable passed to index.php?page=, in this case it would be index.php?page=downloads
if(strcasecmp($page, "downloads")==0){
//insert code here for downloads (or insert downloads.php template)
}

/* or a more efficient (and shorter) method so you wont have to make many if statements*/
$page= $page.".php";
if(file_exist($page)){
include($page);
}
else{
echo "This page is non existent";
}

g1smd

9:08 pm on Sep 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Since for the root of a site you should refer to www.domain.com/ rather than /index.php you might need to code a special case for detecting that root page.

th1chsn

7:01 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



Is there a way in php to say something like this:

$page = the URL after http://

Then I can say

if $page == "www.mysite.com/download.php" {
echo "Hello";
}

supermanjnk

5:18 pm on Sep 17, 2007 (gmt 0)

10+ Year Member



you could do something like this
$page = $_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"];
echo $page;