• 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
https://www.neowin.net/forum/topic/505404-php-switch-menu-system/
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?

  • 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.

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

    • No registered users viewing this page.
  • Posts

    • Doing that has only worked for me with the Enterprise version.
    • I like Neowin a lot, but this "article" is shady and misleading. We need an "editorial" flag and this isn't "news" it's "my cousin's dog's best friend posted on twitter about their snapchat account from their dog's owner that a bad thing happened, so it's NEWS." Thanks
    • Burrrrn. Bought COD WWII last month when it was on sale for PC. Oh well. Excellent game tho, and the PC version plays/looks amazing (and has it's own PC achievements). ...wondering if this is a lesson on waiting on sales. ...also hoping Rise of the Tomb Raider has it's own PC Achievements
    • Google Chrome 137.0.7151.120 (offline installer) by Razvan Serea The web browser is arguably the most important piece of software on your computer. You spend much of your time online inside a browser: when you search, chat, email, shop, bank, read the news, and watch videos online, you often do all this using a browser. Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier. Use one box for everything--type in the address bar and get suggestions for both search and Web pages. Thumbnails of your top sites let you access your favorite pages instantly with lightning speed from any new tab. Desktop shortcuts allow you to launch your favorite Web apps straight from your desktop. Chrome has many useful features built in, including automatic full-page translation and access to thousands of apps, extensions, and themes from the Chrome Web Store. Google Chrome is one of the best solutions for Internet browsing giving you high level of security, speed and great features. Important to know! The offline installer links do not include the automatic update feature. Google Chrome 137.0.7151.120 changelog: [$7000][420697404] High CVE-2025-6191: Integer overflow in V8. Reported by Shaheen Fazim on 2025-05-27 [$4000][421471016] High CVE-2025-6192: Use after free in Profiler. Reported by Chaoyuan Peng (@ret2happy) on 2025-05-31 [425443272] Various fixes from internal audits, fuzzing and other initiatives Download web installer: Google Chrome Web 32-bit | Google Chrome 64-bit | Freeware Download: Google Chrome Offline Installer 64-bit | 128.0 MB Download: Google Chrome Offline Installer 32-bit | 115.0 MB Download page: Google Chrome Portable Download: Google Chrome MSI Installers for Windows (automatic update) View: Chrome Website | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      gatilogistic earned a badge
      One Month Later
    • One Year In
      Custom Greek Shirts earned a badge
      One Year In
    • One Month Later
      Custom Greek Shirts earned a badge
      One Month Later
    • Week One Done
      Custom Greek Shirts earned a badge
      Week One Done
    • Week One Done
      topantidetectbrowser earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      672
    2. 2
      ATLien_0
      281
    3. 3
      Michael Scrip
      223
    4. 4
      +FloatingFatMan
      190
    5. 5
      Steven P.
      146
  • Tell a friend

    Love Neowin? Tell a friend!