justuptime.com - monitor your servers & websites

Im a noob but need help with PHP

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 1 posts

Joined: Jul 2008

hi i am looking to find out how to do this with my website anyone any ideas it would be great.

http://www.domain.what/index.php?page=somthing

how do i do this please. its looks good and profesional.

thanks guys

Anub1s

pr0gr4mm3r's picture
ModeratorSponsor

He has: 823 posts

Joined: Sep 2006

Welcome to the forums, Anub1s! Hope you come back and visit often. Smiling

To answer your question, something like this in your index.php would do the trick:

<?php
   
switch ($_GET['page'])
    {
        case
'something':
            include(
'something.php');
            break;
       
        case
'another_page':
            include(
'another_page.php');
            break;
       
        default:
            include(
'404.php');
    }
?>

Using the switch statement, the appropriate page can be loaded based on what is passed to the $_GET['page'] variable. The default section should load a 404 page because that means that a page was requested that didn't meet any of the previous conditions.

I am curious as to why this looks more professional. Pages with query strings are not easily crawled by search engines, and may give your site a lower ranking. Notice that this site does not make use of them. There are other ways to use dynamic URLs without the use of query strings. Apache's mod_rewrite is one of them.

Greg K's picture
Moderator

He has: 1,664 posts

Joined: Nov 2003

If you have a lot of pages, it is better to use a database for the lookup, as then you can also set up other features such as pages that require a login, etc.

Although you may be tempted to directly call from the $_GET variable (ie. include ($_GET['page']); but DO NOT DO IT! Never directly call an include (or exec, eval, SQL statements) with unprocessed variables especially from the query string, the easiest way for a visitor to put something other than you planned on.

I agree it is better to look into the mod_rewrite to make the url look more professional.

-Greg

[This space intentionally left blank]

Cool Geek Supplies: www.ThinkGeek.com

decibel.places's picture

They have: 665 posts

Joined: Jun 2008

some PHP tutorials/references:

tizag.com

w3schools