+ Reply to Thread
Results 1 to 2 of 2

Thread: Load Pages from one Page via URI

  1. #1
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Load Pages from one Page via URI

    In this tutorial I'm going to show you how you can have people only go through one page for your entire website.
    Functions use:
    1) if/then/else
    2) switch
    3) Global Vars
    4) isset
    5) in_array
    6) include
    7) die

    I'll show the code then explain it.

    PHP Code:
    $page "home";
    if(isset(
    $_GET['p'])){
    $page $_GET['p'];
    }
    ?> 
    That section of code sets the $page variable, which will is very important, to the URI if it is set. (URI is the part of the URL after the ?, in this case it would be "?p=*page*")
    Thats a good start, but it is not very secure... Lets make it safer, shall we?

    PHP Code:
    $allowedpages[0] = "home"//You can change this to your page names
    $allowedpages[1] = "other"//You can change this to your page names
    $allowedpages[2] = "other2"//You can change this to your page names

    $page "home";
    if(isset(
    $_GET['p']) && in_array($_GET['p'], $allowedpages)){
        
    $page $_GET['p'];
    }

    include(
    $page ".html") or die("Could not find page!"); // You can change the .html to your pages' extentions 
    The end of that code is what loads the actual page or if the page doesn't exist it stops the page and displays the error message associated with the problem.

    Demo: http://saumpro.com/scripts/other/uritut/main.php

  2. #2
    luckym is offline x10Hosting Member luckym is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    3

    Re: Load Pages from one Page via URI

    How about doing it without the error message?

    Code:
    if(@is_file($page.".html") == true){ // Checks if the file exists.
          include($page . ".html"); //Load up the intended page
    }else{
          include("home.html"); //Load up your default page
    }

+ Reply to Thread

Similar Threads

  1. No more custom error pages!?
    By pasacom in forum Free Hosting
    Replies: 3
    Last Post: 03-12-2008, 12:50 PM
  2. I need help with public viewing of my page
    By Squeaky Neb in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 10-02-2007, 08:24 PM
  3. Replies: 3
    Last Post: 11-29-2006, 01:38 AM
  4. vBulletin - Optimization !!!!!
    By bin_asc in forum Scripts & 3rd Party Apps
    Replies: 7
    Last Post: 08-05-2005, 04:27 AM

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