Jump to content

[SOLVED] Use GET to display a page, some reason doesn't work.


MadnessRed

Recommended Posts

OK, heres my code.

 

<?php

if ($_GET["page"]="home")
{
include 'index.php';
}

elseif ($_GET["page"]="about")
{
include 'pages/about.php';
}

elseif ($_GET["page"]="contact")
{
include 'pages/contact.php';
}

elseif ($_GET["page"]="links")
{
include 'pages/links.php';
}

elseif ($_GET["page"]="games")
{
include 'pages/games.php';
}

elseif ($_GET["page"]="mm2")
{
include 'pages/mm2.php';
}

elseif ($_GET["page"]="mm2cars")
{
include 'pages/mm2_cars.php';
}

elseif ($_GET["page"]="mm2tracks")
{
include 'pages/mm2_maps.php';
}

elseif ($_GET["page"]="mm2mods")
{
include 'pages/mm2_mods.php';
}

elseif ($_GET["page"]="mm2invert")
{
include 'pages/mm2_invert.php';
}

elseif ($_GET["page"]="portal")
{
include 'pages/portal.php';
}

elseif ($_GET["page"]="prospero")
{
include 'pages/propsero.php';
}

elseif ($_GET["page"]="worms")
{
include 'pages/worms.php';
}

elseif ($_GET["page"]="trackmania")
{
include 'pages/tm.php';
}

elseif ($_GET["page"]="computer")
{
include 'pages/computer.php';
}


else
{
include '404.php';
}
?>

 

so in theory shouldnt this link

 

<a href="http://madnessred.co.cc/page.php?page=about" target="_new">About</a>

 

show pages/about.php?

 

link is below.

 

About

Link to comment
Share on other sites

Also this is a better way to do it:

<?php

switch ($_GET["page"])
{
case "home":
include 'index.php';
break;
case "about":
include 'pages/about.php';
break;
case "contact":
include 'pages/contact.php';
break;
case "links":
include 'pages/links.php';
break;
case "games":
include 'pages/games.php';
break;
case "mm2":
include 'pages/mm2.php';
break; 
case "mm2cars":
include 'pages/mm2_cars.php';
break;
case "mm2tracks":
include 'pages/mm2_maps.php';
break;
case "mm2mods":
include 'pages/mm2_mods.php';
break;
case "mm2invert":
include 'pages/mm2_invert.php';
break;
case "portal":
include 'pages/portal.php';
break;
case "prospero":
include 'pages/propsero.php';
break; 
case "worms":
include 'pages/worms.php';
break;
case "trackmania":
include 'pages/tm.php';
break;
case "computer":
include 'pages/computer.php';
break;
default:
include '404.php';
}
?>

Link to comment
Share on other sites

neither worked, get error message

 

Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10

 

Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10

 

Warning: include() [function.include]: Failed opening 'pages/about.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/grewa/public_html/beltd.co.uk/page.php on line 10

Link to comment
Share on other sites


<?php $page = $_GET["page"];
if (!$page) {
include "/home.php";                                                                  // default page
}
else if($page=="home")                { include "/pages/home.php"; }            // index.php?page=home
else if($page=="about")                { include "/pages/about.php"; }            // index.php?page=about
else if($page=="contact")                { include "/pages/contact.php"; }            // index.php?page=contact
else if($page=="links")                { include "/pages/links.php"; }            // index.php?page=links
else if($page=="games")                { include "/pages/games.php"; }            // index.php?page=games
else if($page=="mm2")                { include "/pages/mm2.php"; }            // index.php?page=mm2
else if($page=="mm2cars")                { include "/pages/mm2cars.php"; }            // index.php?page=mm2cars
else if($page=="mm2tracks")                { include "/pages/mm2tracks.php"; }            // index.php?page=mm2tracks
else if($page=="mm2invert")                { include "/pages/mm2invert.php"; }            // index.php?page=mm2invert
else if($page=="portal")                { include "/pages/portal.php"; }            // index.php?page=portal
else if($page=="prospero")                { include "/pages/prospero.php"; }            // index.php?page=prospero
else if($page=="mm2cars")                { include "/pages/mm2cars.php"; }            // index.php?page=mm2cars
else if($page=="worms")                { include "/pages/worms.php"; }            // index.php?page=worms
else if($page=="trackmania")                { include "/pages/trackmania.php"; }            // index.php?page=trackmania
else if($page=="computer")                { include "/pages/computer.php"; }            // index.php?page=computer
else { echo "<b><h1>404 Error</h1></b>"; }                                // error message
?>

 

You're welcome.

Link to comment
Share on other sites

neither worked, get error message

 

Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10

 

Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10

 

Warning: include() [function.include]: Failed opening 'pages/about.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/grewa/public_html/beltd.co.uk/page.php on line 10

Those errors have nothing to do with the code itself, you've got your paths wrong. My code works fine and is actually MUCH better than your if...elseif approach.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.