+ Reply to Thread
Results 1 to 8 of 8

Thread: URL Question

  1. #1
    zenlok is offline x10Hosting Member zenlok is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    13

    URL Question

    Hi All,

    I am currently designing a site and was wondering if anyone knew of a script that allowed the URL showed in the address box to be showed as something like;

    http://mysite.com/index.php?=home

    And changing "home" to something else to link to another page.

    Any help or ideas would be greatly appreciated.

    Many thanks,

    ZeNLoK

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: URL Question

    You could do that with some basic php. It's easier if you'd want http://mysite.com/index.php?page=home or something like that (notice the 'page=' instead of '=').

    If it was the link I posted you could have a code like this:

    PHP Code:
    <?php
    if($_GET["page"] == "home") {
    include 
    "home.php";
    exit;
    }
    ?>
    <html>
    <!-- real index.php -->
    </html>
    This script would import from "home.php" when page=home is specified.

  3. #3
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: URL Question

    if you don't want the "page=" part to show up: http://mysite.com/index.php?home

    There is a slightly different procedure.

    PHP Code:
    <?php
    if (isset($_GET['home'])) {
        
    //load page named "home"
    } elseif (isset($_GET['something'])) {
       
    //load page named "something"
    } else {
       
    //here load a default page, for instance an error message or something like that to tell users that the page they choose does not exist.
    }
    ?>
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: URL Question

    For a fully general solution,

    1. Put your files in a subdirectory like site_pages, so it will be harder for users to go directly to the page.

    2. I assume they will all have .php extensions

    3a. URL of "index.php?show=portfolio" (substitute 'page', 'request' , 'q' etc for 'show' )
    PHP Code:
    $directory 'site_pages/' ;
    $default_page 'site_pages/default.php' ;

    if( isset( 
    $_GET'show'] ){

      
    $stub $_GET'show'];
     
      if( 
    preg_match(  '/(\.|\/|\\)/' $stub ) ){   ## make sure no .  or /  or \  to foil hackers 
          
    $requested_page $default_page ;
      } else {
          
    $requested_page $directory $stub ".php" ;
          if( ! 
    is_file$requested_page ) ){  ## no file, serve up default
             
    $requested_page =  $default_page ;      
         } 

    } else {

      
    $requested_page =  $default_page ;

    }

    include( 
    $requested_page ) ;

    exit() ; 
    Nothing is always absolutely so.

  5. #5
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: URL Question

    3b URL of "index.php?portfolio" (substitute the page name for 'porfolio' ). Add a elseif (...) { ... } block for each page you make.
    PHP Code:
    <?php
    $directory 
    'site_pages/' ;
    $default_page $directory .  'default.php' ;

    if ( isset( 
    $_GET'index'] )){
      
    $stub 'index';
    } elseif ( isset( 
    $_GET'page2'] )){
      
    $stub 'page2';
    } elseif ( isset( 
    $_GET'page3'] )){
      
    $stub 'page3';
    } else {
      
    $stub =  'default';
    }

    $requested_page $directory $stub ".php" ;
    if( ! 
    is_file$requested_page ) ){
       
    // no file, serve up default
       
    $requested_page =  $default_page ;      


    include( 
    $requested_page ) ;

    exit();
    ?>
    descalzo, you could improve your code by doing a switch... it would be more efficient.
    Oh and you forgot a ) after the if statement.
    Last edited by xav0989; 10-10-2009 at 02:46 PM. Reason: improved code
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: URL Question

    Quote Originally Posted by xav0989 View Post

    descalzo, you could improve your code by doing a switch... it would be more efficient.
    But then if he adds 15 new pages, he has to add 15 new cases to the switch, with the possibility of misspelling a case, etc.
    Nothing is always absolutely so.

  7. #7
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: URL Question

    Quote Originally Posted by descalzo View Post
    But then if he adds 15 new pages, he has to add 15 new cases to the switch, with the possibility of misspelling a case, etc.
    true... I need to stop thinking in terms of my site (my pages do not change much)

    have you seen your typo?
    Last edited by xav0989; 10-10-2009 at 02:47 PM.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  8. #8
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: URL Question

    I'd stay away of any "general" possibilities, if you mess up the slightest bit a hacker can find an easy way in. Maintaining a list of pages is far better.

    Why do you want to be able to do this? If you are just curious as to how it's possible I think the answer has been given many times.
    There are a number of downsides to this too. You'd have to update that page if you want to add a new page. (Did I hear the word typo?) I think it'd be more efficient to just add a file. Also, some search engines don't like urls like that and will just skip them, assuming it's dynamical generated content, not a static page (usually they're only interested in static pages).
    Most of the time you hear questions like this:
    I have this news page with urls like this: news.php?id=15 but I've seen many sites that use urls like news/15/ instead. How is it possible to do this?

    So it's up to you, but in general there would be no need to do this.

+ Reply to Thread

Similar Threads

  1. Is Rand Paul a Freemason?
    By allofus in forum Crossfire
    Replies: 6
    Last Post: 10-02-2009, 04:52 AM
  2. Lottery Website (kind of)
    By admintwo in forum Earning Money
    Replies: 4
    Last Post: 12-29-2007, 05:07 PM
  3. Question about reputation....
    By Swiblet in forum Off Topic
    Replies: 4
    Last Post: 12-17-2007, 12:56 AM
  4. Odd question but will I be banned for this?
    By sielk in forum Free Hosting
    Replies: 3
    Last Post: 09-28-2007, 11:29 AM
  5. SQL Question
    By DizzyTechnology in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 01-16-2007, 07:56 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