• 0

PHP Switch Menu System


Question

Hi!

I have this as a system to switch pages on a website:

<?php

								if (! isset($_GET['page']))
								{
									include('./index.php');

								} else {

									$page = $_GET['page'];

									switch($page)
									{
										case 'home':
											include('./news.php');
											break;

										case 'downloads':
											include('./downloads.php');
											break;

										case 'music':
											include('./music.php');
											break;

										case 'gallery':
											include('./gallery.php');
											break;

										case 'support':
											include('./support.php');
											break;

										case 'history':
											include('./history.php');
											break;

										case 'privacy':
											include('./privacy.php');
											break;

										case 'ucsig':
											include('./ucsig.php');
											break;

										default:
											include('./news.php');
											break;
									}
								}

								?>

However, when you go to something like http://www.mysite.com/index.php then it just says it cannot display the page, it doesnt display the default value. Is there a way to stop this or is it just something I have to put up with?

Cheers,

Peter

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

from the looks of it when you go to just plain old index.php it detects that $_GET['page'] is not set, so it then tries to include index.php, and it carries on in an infinate loop until the server or php processor timeout and you end up with nothing. shouldnt it be including news.php which according to the switch statement is your home page?

Link to comment
Share on other sites

  • 0

This bit of code here:

								if (! isset($_GET['page']))
								{
									include('./index.php');

								}

should be this:

								if (! isset($_GET['page']))
								{
									include('./news.php');

								}

That's what Lyndon was saying. You were checking to see if there was a get, and if there wasn't, you were including the current page which starts an infinite loop and therefore displays an error. The above should work though.

Link to comment
Share on other sites

  • 0

OoOoO i see now.

Gosh that is pretty obvious. From now on i vow to really look at the code and see the logic behind it before i ask :$

Thanks,

Peter

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.