how to make this?<http://something.com/index.php?id=1&
Moderator: General Moderators
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:
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ї'id'];
if(isset($id)) // checks if 'id' was part of the link // checks if 'id' was part of the link
{
if(file_exists("page".$id.".php")) // checks if the page exists
{
include("page".$id.".php"); // includes the page
}
else
{
echo("Page not found."); // gets shown if the page doesn't exist
}
}
else
{
echo("No page requested."); // gets shown if 'id' wasn't part of the link
}
$c =$_GETї'c'];
if(isset($c)) // checks if 'id' was part of the link // checks if 'id' was part of the link
{
if(file_exists("side".$c.".php")) // checks if the page exists
{
include("side".$c.".php"); // includes the page
}
else
{
echo("Page not found."); // gets shown if the page doesn't exist
}
}
else
{
echo("No page requested."); // gets shown if 'id' wasn't part of the link
}
?>
Last edited by md702 on Sat Oct 11, 2003 11:56 am, edited 2 times in total.
I actually made a typo in the code it should be this...... (note the => symbol)
..... I also use it for POST and SESSION as well ........
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.
Code: Select all
<?php
foreach($_GET as $var => $value) { ${$var} = $value; }
?>Code: Select all
<?php
foreach($_POST as $var => $value) { ${$var} = $value; }
foreach($_SESSION as $var => $value) { ${$var} = $value; }
?>Yeah that's about the size of it.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
It might be easier to work with http:///something.com/index.php?menu=1&page=5 though... but it's up to you.
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.md702 wrote:could you review the code Gen-ik:) TY!
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.");
}
?>