Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: index.php?page=

  1. #1
    Kix
    Kix is offline
    New to the CF scene
    Join Date
    Mar 2010
    Location
    Newcastle
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    index.php?page=

    How would I make my my websites page URLs to be like that instead of being...
    index.html, contact.html

    I would like it to look cleaner by using PHP. How would I do this? By the way, It would help if you explained the code because im not too good with PHP. Thanks.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    // put pages into an array, from eg: page.php?page=index.html
    $pages = array("index.html","aboutus.html");

    // check to see if page is valid
    if(in_array($_GET['page'],$pages)){
    // include page requested
      
    include $_GET['page'];
    }else{
    // page doesn't exist
      
    echo 'page not found';


  • #3
    Regular Coder
    Join Date
    Jul 2009
    Posts
    136
    Thanks
    0
    Thanked 7 Times in 7 Posts
    I can't see that looks cleaner. Also search engines supposedly look at file names so a good file name can be useful.

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    This is the way I do it. The following will get you something like index.php?x=shop

    PHP Code:
    if (isset($_GET['x']))
    {
        
    $x explode(':'$_GET['x']);

        switch(
    $x[0])
        {
            case 
    'shop':
                
    shop();
            break;
    }

    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •