+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [PHP] Pages with ids Tutorial

  1. #1
    nightscream is offline x10 Lieutenant nightscream is an unknown quantity at this point
    Join Date
    Feb 2006
    Location
    Hallaar, Belgium
    Posts
    474

    [PHP] Pages with ids Tutorial

    Ok i'll post the first tutorial here, I hope it's a good one
    If you are wondering how people do the url/index.php?id=News this is the tutorial for it
    I hope you understand what I say in this tutorial, I'll try to make it easy.


    Create your main file, index.php
    create your menu, no links yet
    example:
    Code:
    <table width="125" cellpadding="0" cellspacing="0">
    <tr><td>Menu</td></tr>
    <tr><td>News</td></tr>
    <tr><td>Members</td></tr>
    </table>
    now go to the part of your file where you want that the content change
    and put something like this
    Code:
    <?php
    $id = $_REQUEST['id']; // this will get the id of the link, this will be explained later.
    switch($id) { // make a case with the id
    default: include('main.php'); //When page is loaded this will be the main content, put the content in main.php(you can change the name)
    break; // close this case
    case "News": include('news.php'); // The content in news.php will be called when id=News
    break; // close this case
    case "Members": include('members.php'); // The content in members.php will be called when id=Members
    break; // close this case
    } // close switch
    ?>
    You can add more ids in there if you want.

    Now go back to your menu and we are going to add the links
    add this kind of link to your menu
    Code:
    <a href="index.php?id=ID THAT YOU WANT" target="_self">TEXT</a>
    with my example it will be like below.
    the id=News is equal to the case "News" in the php function
    Code:
    <table width="125" cellpadding="0" cellspacing="0">
    <tr><td>Menu</td></tr>
    <tr><td><a href="index.php?id=News" target="_self">News</a></td></tr>
    <tr><td><a href="index.php?id=Members" target="_self">Members</a></td></tr>
    </table>
    This Was the tutorial, I hope you liked it and you learned something.

    Nightscream
    ------------------------------------------------------------------------------------------
    If you have any troubles with a website or a script, just send me a pm.

    I also code websites in xHTML/css, can code javascript and php too if needed

  2. #2
    Fedlerner's Avatar
    Fedlerner is offline Retired Fedlerner is an unknown quantity at this point
    Join Date
    Aug 2006
    Location
    Buenos Aires, Argentina
    Posts
    12,923

    Re: [PHP] Pages with ids Tutorial

    Nice!!!
    I read this one in your website :P
    Federico Lerner
    Former x10Hosting Administrator - Staff Manager

  3. #3
    Zenax's Avatar
    Zenax is offline Lord Of The Keys Zenax is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    The Brilliant United Kingdom
    Posts
    1,339

    Re: [PHP] Pages with ids Tutorial

    Code:
    <?php 
    
    
    if( isset($HTTP_GET_VARS['page']) || isset($HTTP_POST_VARS['page']) )
    {
        $page = ( isset($HTTP_GET_VARS['page']) ) ? $HTTP_GET_VARS['page'] : $HTTP_POST_VARS['page'];
        $page = htmlspecialchars($page);
    }
    else 
    {
        $page = "";
    }
    
    switch( $page )
        {   
    	
    		 case "1":
    		include("1.php");
    	   break;
    	    
             case "2":
            include("2.php");
           break;
    
             case "3":
            include("3.php");
           break;
    
             case "4":
            include("4.php");
           break;
    
          default:
    	  include("inc/main.php");
        break;
    }
    
    ?>
    This is the php code I use to do it! Could you tell me what the difference is and which is better?
    Regards,
    Zenax

  4. #4
    t2t2t's Avatar
    t2t2t is offline x10 Elder t2t2t is an unknown quantity at this point
    Join Date
    Sep 2006
    Location
    Europe, Estonia
    Posts
    690

    Re: [PHP] Pages with ids Tutorial

    His code has everything on one page and uses html function for moving thru page.
    This post has been marked spam 52 times.


  5. #5
    jaygreentree is offline x10 Sophmore jaygreentree is an unknown quantity at this point
    Join Date
    Sep 2006
    Posts
    144

    Re: [PHP] Pages with ids Tutorial

    I prefer to use the code below because its more secure:
    PHP Code:
    <?
    if (isset($_GET['id']) && file_exists('/path/to/page/'.$_GET[id].'.php')) {
    include 
    '/path/to/page/'.$_GET[id].'.php';
    } else {
    include(
    "/path/to/page/main.php");
    }
    ?>
    Then the links would looks like
    HTML Code:
    <a href="index.php?id=page">Page Name</a>

  6. #6
    Woolie's Avatar
    Woolie is offline x10 Lieutenant Woolie is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    The Fletcher Memorial
    Posts
    431

    Re: [PHP] Pages with ids Tutorial

    I'm slightly curious to know why everyone loves to use GET globals for navigation when there is no database present? What is the point? You don't gain anything, it just means unnecessary code to edit when you want to add a navigation link.

    I mean, it is (usually) necessary to use them for database based content management type systems, but when I create things like that, I always try to use mod_rewrite (where possible) to make them look more friendly to the human.

    Anyway, apart from that, I suppose it's a good tutorial... If you really want to waste your time making extra work for yourself, when the idea of using programming languages (especially PHP) is to make it easier for you. Ummm, does that really make sense?

  7. #7
    jaygreentree is offline x10 Sophmore jaygreentree is an unknown quantity at this point
    Join Date
    Sep 2006
    Posts
    144

    Re: [PHP] Pages with ids Tutorial

    The way I posted above you just add the link to the menu and create the page. My code doesn't have to be updated everytime like the ones that use case. That's the reason I use mine.

  8. #8
    nightscream is offline x10 Lieutenant nightscream is an unknown quantity at this point
    Join Date
    Feb 2006
    Location
    Hallaar, Belgium
    Posts
    474

    Re: [PHP] Pages with ids Tutorial

    that's true but I use this way maybe i'll try yours, just a tutorial;)
    ------------------------------------------------------------------------------------------
    If you have any troubles with a website or a script, just send me a pm.

    I also code websites in xHTML/css, can code javascript and php too if needed

  9. #9
    dest581 is offline x10 Lieutenant dest581 is an unknown quantity at this point
    Join Date
    Sep 2006
    Posts
    348

    Re: [PHP] Pages with ids Tutorial

    For codes where it just changes x to x.php, make sure that you filter out any requests containing ../ or http://

  10. #10
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Re: [PHP] Pages with ids Tutorial

    nice one ! i alwasys used to wonder what the id stands for
    glad to resolve problems in c++ n php

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Network Folder Sharing Tutorial
    By TheJeffsta in forum Computers & Technology
    Replies: 0
    Last Post: 03-31-2006, 02:33 AM
  3. [PHP] Dynamic Includes Tutorial
    By Bryon in forum Tutorials
    Replies: 3
    Last Post: 12-16-2005, 01:34 PM
  4. Replies: 7
    Last Post: 09-16-2005, 10:27 AM
  5. [PHP] Placing the Ads in PHP Pages
    By Chris in forum Tutorials
    Replies: 22
    Last Post: 06-04-2005, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers