
July 20th, 2004
09:37 PM
Web Designer
Status: Offline!
wont set var if var is empty
this is my code
<?php
if( !isset( $_GET['page'] ) || empty( $_GET['id'] ))
{
$page == "home.html";
}
else
if(preg_match("/html/", $page)){
$page == $page.'.html';
}
elseif(preg_match("/php/", $page)){
$page == $page.'.php';
}
?>
but if the page is opened and no $page is set it wont then set the page as home.html plz help ive tried lots of different things but i cant fix it
___________________

Fresh Web
Free 5mb Storage
Last edited by Fresh, July 20th, 2004 09:48 PM (Edited 1 times)

July 20th, 2004
09:45 PM
Neversidian
Status: Offline!
I'm lost. What are you trying to do?
___________________
"Hey, **** YOU!"

July 20th, 2004
09:56 PM
what could you possibly want to know about me?
Status: Offline!
I'm not quite sure what you're trying to do either, but my guess is
that you want to assign something to $page, right?
so...
<?php
if( !isset( $_GET['page'] ) || empty( $_GET['id'] ))
{
$page = "home.html"; // changed something here
}
else
if(preg_match("/html/", $page)){
$page = $page.'.html'; // changed something here
}
elseif(preg_match("/php/", $page)){
$page = $page.'.php'; // changed something here
}
?>

July 20th, 2004
10:38 PM
Web Designer
Status: Offline!
nope it wont change now
___________________

Fresh Web
Free 5mb Storage

July 20th, 2004
10:41 PM
Neversidian
Status: Offline!
Maybe the last elseif should be an else?
___________________
"Hey, **** YOU!"

July 20th, 2004
11:09 PM
Neversidian
Status: Offline!
why bother with preg_match ?
From sabrina's code
<?php
if( !isset( $_GET['page'] ) || empty( $_GET['id'] ))
{
$page = "home.html"; // changed something here
}
else
if(strpos( $page, 'html')!==false){
$page = $page.'.html'; // changed something here
}
elseif(strpos( $page, 'php')!==false){
$page = $page.'.php'; // changed something here
}
?>
But just out of curiosity? Where is $page coming from? Try maybe $_GET['page'] since i get a feeling $page is meant to be using register globals, which most production servers will have disabled.
Also, the way you're doing it, i'm assuming you're looking for $page to having something like idiot.html or idiot.php .. but the way you're doing it you'll end up with idiot.html.html or idiot.php.php ....
___________________
angelessme, antagonising neverside members, staff and administration since 2001.
Last edited by angelessme, July 20th, 2004 11:14 PM (Edited 1 times)

July 20th, 2004
11:16 PM
Web Designer
Status: Offline!
no i own the server lets say if u wanted to goto contacts page u would go www.yoursite.com/index.php?page=contacts
but if i wanted to just goto www.yoursite.com/ it will display the home page the reason for all this trouble is so i can have this bit after the code
[PHP]<iframe src="<?php echo $page; ?>" name="_text" width="737" height="100%" frameborder="0" scrolling="yes"></iframe>[PHP]
___________________

Fresh Web
Free 5mb Storage

July 20th, 2004
11:19 PM
Neversidian
Status: Offline!
Errr.. okay.. so does your site use .html or .php driven pages?
Because either way, the method you're using wont work since you're looking for 'html' or 'php' in either, and neither will be found since your $_GET['page'] will just be 'contacts' .. do you follow?
___________________
angelessme, antagonising neverside members, staff and administration since 2001.

July 21st, 2004
02:48 AM
Neversidian
Status: Offline!
should this
<?php
if( !isset( $_GET['page'] ) || empty( $_GET['id'] ))
?>
be this
<?php
if( !isset( $_GET['page'] ) || empty( $_GET['page'] ))
?>
?
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

July 21st, 2004
03:11 AM
Neverside Newbie
Status: Offline!
Wouldn't using switch statements be easier?