I've seen the above mentioned system at a lot of php/asp scripted web sites. How do I do it? I guess the general idea is to have a specific page n:o and then let the receiving page determine which page is wanted. Like, ?page=1 (home) ?page=23 (news) page=34 (links).

I have seen a nice code sample (I even think it was on this site) in this subject, but haven't been able to find it by searching. Thanks in advance for your help!

    [url]http://www.mysite.com/mypage.php?ref=1[/url]
    

    Just a few pointers, as you will already know the above is a URL. The URL is broken down by protocol ([url]http://[/url]) domain (www.mysite.com) request (mypage.php) and query string(ref=1). The query string is the bit your interested in. IIRC the web server parses these bits, and also makes them available to whatever executables are defined (PHP in this case). In PHP they are available in the $GLOBALS array under HTTP_SERVER_VARS. In older versions of PHP this was also made available in the $HTTP_SERVER_VARS[] array, but it recent versions the query string parameters are placed in special superglobal variable $_GET[]. Superglobal means that they are automatically available to every scope in PHP.

    So get access to the query string use $GET['name'] if they are part of a link, or supplied from an HTML form with a GET action, or $POST['name'] if they are supplied from a form with a POST action.

    A quick quote on the difference between GET and POST:

    In terms of mechanics, they differ in how parameters are passed to the CGI script. In the case of a POST request, form data is passed on STDIN, so the script should read from there (the number of bytes to be read is given by the Content-length header). In the case of GET, the data is passed in the environment variable QUERY_STRING. The content-type
    (application/x-www-form-urlencoded) is identical for GET and POST requests.

    Hope this helps 😉

      Yes, it was a nice explanation. But I'd like a more in-depth example of a good usage of this, like an article system example or when to use it on your own homepage and how. 🙂

        There's not really a good usage as such. It is part of the mechanism for getting data from the client to the server and so there is only really one usage.

        http://www.mysite.com/mypage.php?ref=1
        <?php
        $ref = $_GET['ref']; // Variable $ref now contains the querystring value ref (1)
        
        if(isset($_GET['ref']) && is_numeric($_GET['ref'])){
          $sql = "SELECT article FROM news WHERE id = ".$_GET['ref'];
          mysql_query($sql);
          etc...
        

          I see. Sometimes you think things are harder then they are. Thank you very much for your helpful advice!

            <?php
            $ref = $_GET['ref']; // Variable $ref now contains the querystring value ref (1)
            
            if(isset($_GET['ref']) && is_numeric($_GET['ref'])){
              $sql = "SELECT article FROM news WHERE id = ".$_GET['ref'];
              mysql_query($sql);
              etc...
            

            [/B][/QUOTE]

            Wouldn't it be easier to store it as a variable there? Or does it not matter?

              Easier in that you would have to type $_GET['ref'] every time, but then also taking up more memory 🙂

              It was just to illustrate usage 🙂

                I use this script for my website. What I use it for is to call pages to a single page.

                In essence, all I have to do is code 1 page with no content, and call it, let's say page.php.

                Then, wherever my content goes I use a script like that to call whatever page that has the content I want to that blank page. It's very useful because I don't have to go through all my pages redoing the code for the layout everytime I do a new layout.

                On my website, the main page is pages.php

                If you go here:

                http://www.hateralligator.com/pages.php

                You will see an error in the content area. That is because there is no variable (?id=blablah). If you add one, let's say, tutorials. Then it will load my tutorials page. If you put about, then it will load the about page.

                http://www.hateralligator.com/pages.php?id=tutorials
                http://www.hateralligator.com/pages.php?id=about

                It is extremely useful to me because I can generate an infinite amount of pages and only have to code 1 page and use the ?id= to generate what goes into the content box.

                Hope this helps show a use for it.

                -Hater Alligator

                  2 months later

                  Hater Alligator >> Do you have some sort of tutorial for how to do this? I have looked everywhere for a tutorial about this! 🙁

                    E-mail me, ill send you a tutorial on it.

                    webmaster[at]hateralligator.com

                    That's my email, obviously, replace [at] with @, lol.

                    -Hater Alligator

                      Write a Reply...