How to pass variables throught the URL into my PHP page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcphearson2345
    New Member
    • Nov 2007
    • 4

    How to pass variables throught the URL into my PHP page?

    how do i get the query from an url to change variables in my website

    for example my website is called www.example.com

    so the query would be www.example.com?qwerty

    and i want a link in my site to change as the query does

    so a link in my site would change to www.thescripts.com/qwerty

    is there away i can do this please let me know i am very desperate to find out

    thanks in advance!
    Last edited by Atli; Nov 2 '07, 09:01 PM. Reason: Changed thread title to better describe it's contents.
  • jx2
    New Member
    • Feb 2007
    • 228

    #2
    try:
    [php]
    echo $_GET['variableName'];
    echo $GLOBALS['QUERY_STRING']; //WHOLE THING
    [/PHP]

    REGARDS
    JX2

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi mcphearson. Welcome to TSDN!

      You can add variables, via the GET protocol, to the URL and fetch them in your code.

      If you want to pass a value for user ID, you might have an URL that looks like this:
      Code:
      www.example.com/page.php?userID=1
      Then you could fetch this variable via the $_GET super-global in your PHP code:
      [code=php]
      echo "User ID: ". $_GET['userID'];
      [/code]
      You can have more than one variable, just separate them with a & sign:
      Code:
      www.example.com/page.php?userID=1&userName=yourName
      P.S.
      I've edited the thread's title. Please take a look at our Posting Guidelines for tips on how to create good thread titles.

      Comment

      • mcphearson2345
        New Member
        • Nov 2007
        • 4

        #4
        thanks very much for your help

        although im still confused

        im not that great with php

        how would i include that code in to my site

        would i put that code in the link that i want to change

        for example

        <a href="http://www.domain.com/echo "User ID: ". $_GET['userID'];">

        so will the link change from the / onwards.. to the query in the Url??


        thanks in

        Ps im using dreamweaver if that makes any difference

        Comment

        • jx2
          New Member
          • Feb 2007
          • 228

          #5
          Originally posted by mcphearson2345
          <a href="http://www.domain.com/echo "User ID: ". $_GET['userID'];">
          no llike that :/
          you have two choices
          [php]
          <html>
          <body>
          <a href="<?php echo "$PHP_SELF?user ID=$_GET['userID']"; ?>" >link</a>
          </body>
          </html>
          [/php]
          or you can echo everything :-)
          [php]
          <?php
          echo "<html>
          <body>
          <a href='$PHP_SELF ?userID=$_GET['userID']'>link</a>
          </body>
          </html>
          ";
          [/php]
          regards
          jx2

          Comment

          • mcphearson2345
            New Member
            • Nov 2007
            • 4

            #6
            Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /data/members/paid/b/i/binco.co.uk/htdocs/splashpage/apple.php on line 237

            that is the message i keep getting

            i really dont know what im doing wrong...

            i know you guys have much better things to do and i dont want to put you out!

            is there a way i can send you all my html code and you coud edit it then send it back??

            pleaes let me know

            and thanks very much for all your help so far

            Comment

            • post
              New Member
              • Sep 2007
              • 17

              #7
              Originally posted by mcphearson2345
              Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /data/members/paid/b/i/binco.co.uk/htdocs/splashpage/apple.php on line 237

              that is the message i keep getting

              i really dont know what im doing wrong...

              i know you guys have much better things to do and i dont want to put you out!

              is there a way i can send you all my html code and you coud edit it then send it back??

              pleaes let me know

              and thanks very much for all your help so far
              I don't know which example you picked but I fixed both of them so you can use either one.
              [php]
              <?php
              echo "<html>
              <body>
              <a href='$PHP_SELF ?userID=$_GET[userID]'>link</a>
              </body>
              </html>
              ";
              ?>
              [/php]
              [html]
              <html>
              <body>
              <a href="<?php echo "$PHP_SELF?user ID=$_GET[userID]"; ?>" >link</a>
              </body>
              </html>
              [/html]

              Comment

              • vijcbe
                New Member
                • Sep 2007
                • 16

                #8
                One can use $_GET or $_REQUEST method to pass a variable and the suggestions given by our forum friends are very correct. But, I insist to store the variable in a session variable and make the session alive until you are done with your job. Once your job is done, you can unset the session variable. You cannot send data through URL, which you wanted to be encrypted, since, data sent are visible in the address bar. I reckon this piece of information will help you.
                VJ

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  I think you're all missing his questions.

                  He asked how to change

                  [code=php]
                  www.example.com ?username
                  [/code]
                  to
                  [code=php]
                  www.example.com/username
                  [/code]

                  I have an inkling he's likely to be talking about virtual hosting, is it? You know how MySpace has www.myawfulspac e.com/usersprofile

                  I believe this would be done through .htaccess, but i really have no idea.

                  Also, i don't even know whether this is what he asked ¬_¬ It just seemed no one took into consideration the /qwerty he talked about.

                  If anyone knows any good tutorials on virtual hosting(not sure if it is that) could you post them please?

                  Thanks :)

                  Comment

                  • mcphearson2345
                    New Member
                    • Nov 2007
                    • 4

                    #10
                    Ive done it

                    id like to thankyou sooo much. you have made my day. i used some of the code that was posted and i had to alter it a little, but it works perfect.

                    thankyou once again

                    i will be recomending this site to everyone and i will sure be back next time i need help

                    Comment

                    • vijcbe
                      New Member
                      • Sep 2007
                      • 16

                      #11
                      Yes.. I missed it completely..
                      Sorry..
                      VJ

                      Comment

                      Working...