5 replies
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!
#php
  • Profile picture of the author mywebwork
    Originally Posted by Amir Khan View Post

    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!
    I think that this would be interpreted as a directory called "variable" and not as a actual variable - or am I missing something?

    Bill
    {{ DiscussionBoard.errors[1690138].message }}
  • Profile picture of the author customertools
    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
    {{ DiscussionBoard.errors[1690152].message }}
  • Profile picture of the author CJames
    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.
    {{ DiscussionBoard.errors[1690153].message }}
  • Profile picture of the author Amir Khan
    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.
    {{ DiscussionBoard.errors[1690903].message }}
  • Profile picture of the author TristanPerry
    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
    Signature
    Plagiarism Guard - Protect Against Content Theft
    {{ DiscussionBoard.errors[1691231].message }}

Trending Topics