Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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