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 12 of 12

Thread: variable in URL

  1. #1
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts

    variable in URL

    I need help with getting a variable into the url like

    Code:
    // example url http://example.co.uk
    // how do i get it to show http://example.co.uk/index.php?page=news
    
    and how do i redirect the variable news to news.html?
    thanks,
    newcomer Rafiki

  • #2
    New Coder
    Join Date
    Aug 2006
    Location
    Netherlands
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would say you just code:
    PHP Code:
    http://example.co.uk/index.php?page=news 
    But that is probably not what you mean. Please elaborate a little bit more on your problem. Do you generate the URL yourself or ?

    Ronald
    RTFM is an almost extinct art form, it should be subsidized.

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    here is the perfect example i found whilst browsing web
    Code:
    www.tip.it/runescape/index.php?page=prayer_guide.htm
    if this gives you a better idea

    thanks
    Rafiki

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?php
    // Example URL: http://example.co.uk/index.php?page=news 
    // Enter page names here
    $page = array('news','blah','de','blahdeblah');
     
    if(isset(
    $_GET['page'])){
    if(
    in_array($_GET['page'],$page)){
    //includes html page into the index.php page
    include $_GET['page'].'.html';
    }else{
    include 
    'index.php';
    }
    }
    ?>
    Quick simple way
    Last edited by Nightfire; 08-24-2006 at 04:24 PM.

  • #5
    New Coder
    Join Date
    Aug 2006
    Location
    Netherlands
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still not. DOn't give a sample output, show the code you have.
    RTFM is an almost extinct art form, it should be subsidized.

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    atm i dont have any code at all, i have no php experience just html and javascript, i just have the page which is exampled as news.html and index.html which needs to be converted into php i believe

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Nightfire
    PHP Code:
    <?php
    // Example URL: http://example.co.uk/index.php?page=news 
    // Enter page names here
    $page = array('news','blah','de','blahdeblah');
     
    if(isset(
    $_GET['page'])){
    if(
    in_array($_GET['page'],$page)){
    //includes html page into the index.php page
    include $_GET['page'].'.html';
    }else{
    include 
    'index.php';
    }
    }
    ?>
    Quick simple way
    with this code would i just add the html link like
    Code:
    <a href="http://example.com/index.php?page=news>News</a>?

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I'm also a bit confused, but maybe this is what they want:

    Code:
    <?php
    
    // example url http://example.co.uk
    // how do i get it to show http://example.co.uk/index.php?page=news
    
    $page = $HTTP_GET_VARS['page'];
    
    //and how do i redirect the variable news to news.html?
    
    $location = $page.".html";
    header ("location: $location");
    
    ?>

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Yep. Just make sure the code I put up is where you want the html page adding into your php page. Can also make it redirect to your html page if you want that instead of it being included

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Quote Originally Posted by mlseim
    I'm also a bit confused, but maybe this is what they want:

    Code:
    <?php
     
    // example url http://example.co.uk
    // how do i get it to show http://example.co.uk/index.php?page=news
     
    $page = $HTTP_GET_VARS['page'];
     
    //and how do i redirect the variable news to news.html?
     
    $location = $page.".html";
    header ("location: $location");
     
    ?>
    Using depreciated code there and not even any basic checking

  • #11
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    ill go with nights options thanks so much night, thanks other for input aswell

  • #12
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    night this is my out put code, obviosly the index.php will contain more html,
    PHP Code:
    <html> <head> <title>Example Page</title></head>

    <body> <?php

    $page 
    = array('news','about','contact','disclaimer');
    if(isset(
    $_GET['page'])){
    if(
    in_array($_GET['page'],$page)){
    include 
    $_GET['page'].'.html';
    }else{
    include 
    'index.php';
    }
    }
    ?>

    <a href="/index.php?page=news>News</a>
    </body></html>


  •  

    Posting Permissions

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