Results 1 to 6 of 6

Thread: [PHP] Get variables from URL

  1. #1
    210
    posts
    Registered User

    [PHP] Get variables from URL

    hi...

    Is it possible to get information from the url and put it into a variable?

    So:
    PHP Code:
    somepage.php?member=someuser 

    becomes:

    (somepage.php code)
    PHP Code:
    $member someuser

    thanks

  2. #2
    if (isset($_GET['member'])) {
    $member = $_GET['member'];
    }

    $_GET['member'] represents the URL variable... you should use some sort of test (like isset()) to see if it is present, this will avoid a php error if the URL is just somepage.php

  3. #3
    210
    posts
    Registered User
    thanks, it worked a treat

    but im not sure what you mean by:


    "you should use some sort of test (like isset()) to see if it is present"

  4. #4
    depending on your PHP settings, the server will throw an error at you if you just say $member = $_GET['member']; and there is no member=something in the URL.

    So to avoid that, you can use the isset function. it returns a bool variable so you can just use it in a quick if statement like i did (above). it checks to see if the member variable IS SET in the URL

  5. #5
    Quote Originally Posted by chunk
    thanks, it worked a treat

    but im not sure what you mean by:


    "you should use some sort of test (like isset()) to see if it is present"



    when you use isset(); this means that you ask PHP if a particular variable has a value. and it returns "true" or "false".

    for example: you want to know if variable $chunk has used already or has a value. it looks like this.


    PHP Code:
    $answer = isset($chunk); 

    as you see. variable $chunk has no value. that means the value of $answer is false or 0 ...

    in sentence we ask php that:

    is $chunk has a value or already set?

    lets have other example:



    PHP Code:
    $chunk='hello';
    $answer = isset($chunk); 

    now the $chunk has a value or set. that means our $answer returns true or 1

  6. #6
    210
    posts
    Registered User
    Thanks, Melvijin, that cleared it up loads

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012