I want a variable from the URL

Discussion in 'PHP' started by Jim bob 9 pants, Dec 28, 2005.

  1. #1
    How in php do I get the inbound URL and use its variables?

    ie

    www.somesite.com/town.php/looe

    I want to get Looe and use it to create a redirect to another URL

    Any help would be great

    Jamie
     
    Jim bob 9 pants, Dec 28, 2005 IP
  2. Sham

    Sham Peon

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what is looe? is it a variable or a value?

    You can do this:

    www.somesite.com/town.php?looe=5

    and in town.php do this:

    $looe = $_GET['looe'];

    and that will give you a variable called $looe which has the valye 5
     
    Sham, Dec 28, 2005 IP
  3. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #3
    town1.php?town=looe

    is the actual URL, so

    $town=$_GET['town']

    and then $town would be the value, ie looe in this example

    Thanks
     
    Jim bob 9 pants, Dec 28, 2005 IP
  4. MaxPowers

    MaxPowers Well-Known Member

    Messages:
    264
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    #4
    depending on your URL logic and if you have any control over the incoming URL you can also use something like

    $url = $_SERVER['PHP_SELF'];
    $array = explode("/",$url);
    $variable = $array['4'];

    But this method would only work with one type of URL at a time.


    If this is a link from your own site, Apache's mod_rewrite would offer you the best option and allow you to redirect the browser from the 'server', not from a 'file being stored on the server'

    using htaccess on shared hosting...

    RewriteEngine On
    RewriteRule ^town\.php/([a-zA-Z0-9]*)$ redirected-destination.page?info=$1

    where $1 is the part of the URL that changes... you get this from the ([a-zA-Z0-9]*) in the first half of that code.
     
    MaxPowers, Dec 28, 2005 IP
  5. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thats great people, its working thank you very much, happy new year!!
     
    Jim bob 9 pants, Dec 28, 2005 IP
  6. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Jim bob 9 pants, Dec 29, 2005 IP