how to make this?<http://something.com/index.php?id=1&

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

User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I will definitely end up using that in the future genik, thanks man.
md702
Forum Newbie
Posts: 5
Joined: Fri Oct 10, 2003 12:57 am

Post by md702 »

what if you wanted to include 2 different pages as part of the link, what would the index page look like?

For instance, if i wanted: http:///something.com/index.php?menu=1&id=5

where it would load menu 1 page and page5

NM, i think i did it myself:

Code: Select all

<? 
$id =$_GET&#1111;'id']; 
if(isset($id)) // checks if 'id' was part of the link // checks if 'id' was part of the link 
&#123; 
     if(file_exists("page".$id.".php")) // checks if the page exists 
     &#123; 
          include("page".$id.".php"); // includes the page 
     &#125; 
     else 
     &#123; 
          echo("Page not found."); // gets shown if the page doesn't exist 
     &#125; 
&#125; 
else 
&#123; 
     echo("No page requested."); // gets shown if 'id' wasn't part of the link 
&#125; 

$c =$_GET&#1111;'c']; 
if(isset($c)) // checks if 'id' was part of the link // checks if 'id' was part of the link 
&#123; 
     if(file_exists("side".$c.".php")) // checks if the page exists 
     &#123; 
          include("side".$c.".php"); // includes the page 
     &#125; 
     else 
     &#123; 
          echo("Page not found."); // gets shown if the page doesn't exist 
     &#125; 
&#125; 
else 
&#123; 
     echo("No page requested."); // gets shown if 'id' wasn't part of the link 
&#125; 


?>
Last edited by md702 on Sat Oct 11, 2003 11:56 am, edited 2 times in total.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I actually made a typo in the code it should be this...... (note the => symbol)

Code: Select all

<?php
foreach($_GET as $var => $value) { ${$var} = $value; } 
?>
..... I also use it for POST and SESSION as well ........

Code: Select all

<?php
foreach($_POST as $var => $value) { ${$var} = $value; } 
foreach($_SESSION as $var => $value) { ${$var} = $value; } 
?>
I normally prefix the vars with a letter so I know what's what in the script. For example my session vars are prefixed with a s_ so I access them with $s_username and so on.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

md702 wrote:what if you wanted to include 2 different pages as part of the link, what would the index page look like?

like: http:///something.com/index.php?menu=1&id=5

where it would load menu 1 page and page5
Yeah that's about the size of it.

It might be easier to work with http:///something.com/index.php?menu=1&page=5 though... but it's up to you.
md702
Forum Newbie
Posts: 5
Joined: Fri Oct 10, 2003 12:57 am

Post by md702 »

could you review the code Gen-ik:) TY!
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

md702 wrote:could you review the code Gen-ik:) TY!
Your code looks ok (I've cleaned it up a bit) so the best thing to do is just to test it really. If you are sending ID= and MENU= via the link remeber that those are the names of the variables you will need to use.

Code: Select all

<?php
$id = $_GET['id']; 
if(isset($id))
{ 
     if(file_exists("page".$id.".php"))
     { 
          include("page".$id.".php");
     } 
     else 
     { 
          echo("Page not found.");
     } 
} 
else 
{ 
     echo("ID was not set.");
} 

$menu = $_GET['menu']; 
if(isset($menu))
{ 
     if(file_exists("side".$menu.".php"))
     { 
          include("side".$menu.".php");
     } 
     else 
     { 
          echo("Menu not found.");
     } 
} 
else 
{ 
     echo("MENU was not set.");
}
?>
Post Reply