Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

114 users online



wont set var if var is empty

wont set var if var is empty

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 3
Fresh

Fresh

Web Designer
Status: Offline!

wont set var if var is empty

this is my code

PHP:

<?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

___________________

http://www.fweb.ws/images/design/fresh.gif
Fresh Web
Free 5mb Storage

Last edited by Fresh, July 20th, 2004 09:48 PM (Edited 1 times)

Stevie

Stevie

Neversidian
Status: Offline!

I'm lost. What are you trying to do?

___________________

"Hey, **** YOU!"

sabrina

sabrina

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:

<?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
  
}

?>

Fresh

Fresh

Web Designer
Status: Offline!

nope it wont change now

___________________

http://www.fweb.ws/images/design/fresh.gif
Fresh Web
Free 5mb Storage

Stevie

Stevie

Neversidian
Status: Offline!

Maybe the last elseif should be an else?

___________________

"Hey, **** YOU!"

angelessme

angelessme

Neversidian
Status: Offline!

why bother with preg_match ?
From sabrina's code

PHP:

<?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)

Fresh

Fresh

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]

___________________

http://www.fweb.ws/images/design/fresh.gif
Fresh Web
Free 5mb Storage

angelessme

angelessme

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.

BigToach

BigToach

Neversidian
Status: Offline!

should this

PHP:

<?php
if( !isset( $_GET['page'] ) || empty( $_GET['id'] ))
?>

be this

PHP:

<?php
if( !isset( $_GET['page'] ) || empty( $_GET['page'] ))
?>

?

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

evan

evan

Neverside Newbie
Status: Offline!

Wouldn't using switch statements be easier?

Page 1 out of 3
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0107 seconds.