Php GET

by 5 replies
6
I know how to grab variables from a url when they are defined like here:

$_GET['page']
www.site.com/index.php?page=variable

but how would I grab and use the variables that come after a /
for example:
www.site.com/variable

It it possible to grab the variable after the slash?

Thanks in advance!
#programming #php
  • I think that this would be interpreted as a directory called "variable" and not as a actual variable - or am I missing something?

    Bill
  • I'm guessing that site.com/variable is rewritten using modrewrite. You should be able to do a print_r($_get) or print_r($_request) and figure out what that variable name is and its value.

    -Brad
  • Hi Amir,

    You could create an .htaccess that pushes everything toward a central index.php script. I use the Zend Framework which uses 'routes' to parse URLs. I can't post URLs, but do a Google search for 'zend framework routes'.

    A framework might be a bit too much if you're writing a small script, but maybe you could rip out part of the framework code that handles the URL routing and use it in your code.

    I don't have a lot of experience with other frameworks, but I'm sure they could handle URLs in the same way.
  • I want it on a very small scale, here is an example:
    PHP Code:
    < ? p h p 
                
    val =  GET ['watch']; 
                $ 
    error = @ include ($  val '-content.html');
            
    ?>
             <center><h2><a h ref="< ?p h p echo "hd.ph p?watch=".Array ['watch']; ?>Watch This Episode in HD</a></h2></center> 
    Thats my current set up for a video site, where instead of having to manulay entering hd links for each episode, the script grabs episode from the current url, so the hd link is easily generated.

    The problem is I want to do this exact same thing on a wordpress site, but I am a bit clueless.
  • Everyone's over-complicating this. Just go from the $_SERVER[ 'PATH_INFO' ] variable. So:

    $vars = explode('/', $_SERVER['PATH_INFO']);

    Would be used to achieve SEO URLs.

    And to the poster above (mywebwork), this method relies on the Apache callback functionality - so whilst it *is* the syntax of a directory, since the directory doesn't exist, Apache starts traversing back through the URL to find a valid part of the URL.

    This is how SEO-URLs are achieved
  • Banned
    [DELETED]

Next Topics on Trending Feed