SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Las Vegas, NV
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    POST and GET variable problem

    Hi, I am still learning my way around PHP and have come across a problem I cannot find a solution for.

    I need to have a script bring in a variable that can come in either via POST or GET.

    I would imagine this would be quite simple, but I give up.

    For most of the scripts, I have used:

    $page = $_GET['page'];

    OR

    $page = $_POST['page'];

    But, for this one particular script it need to be able to accept the "page" variable whether it comes in via GET or POST. I am doing this because Register Globals has recently been changed to OFF on my server. The code is not OOP.

    TIA,

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Yep, this'll do the trick
    PHP Code:
    /*
        instead of either of these methods
    */
    $var $_GET['var'];
    $var $_POST['var'];

    /*
        try using this
    */
    $var $_REQUEST['var']; 

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    try this way:
    PHP Code:
    $var = isset($_POST['var']) ? $_POST['var'] : $_GET['var']; 

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    algis, that's a waste of bytes, just use the $_REQUEST array.

  6. #6
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Las Vegas, NV
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, the $_REQUEST worked great. Wondering why I missed it when searching earlier for an answer. I guess it would help if I had a better understanding of what I was reading


Bookmarks

Posting Permissions

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