Results 1 to 6 of 6

Thread: if ($_POST[op]!="ds"

  1. #1
    Join Date
    Feb 2008
    Location
    Melbourne, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile if ($_POST[op]!="ds"

    Hi! I am just starting to read about PHP and have got stuck on the code I have put in the title. I would really appreiciate what the array "op" is/stands for and how "ds" can have a value.

    Regards

    Ian

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The array is $_POST, not op. op is the key used to access an element of that associative array (and should really be in quotes, since it's probably meant to be a string). "ds" is another string.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    POST data is usually sent from a form, with method="post" (or through flash, ajax via Javascript, and a few other much less common methods).
    The form field was likely named 'op', and that checks, likely, if 'ds' was the value sent through that field.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Aug 2007
    Location
    Ohio
    Posts
    79
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Default

    Hello! If you pick apart that expression ( $_POST[op]!="ds" ), there are there main parts:

    The first is $_POST[op]. One of the only ways to interact with a webpage is to send GET or POST data. GET data is appeneded onto the end of the url. A good example is the url of this thread. showthread.php?t=29545. The question mark marks the beginning of the GET data. If your php script wanted to make use of what was passed by the url like that, you could reference it like so:
    Code:
    echo $_GET['t'];  // would print 29545 to the screen if it were in this thread's file
    The other method of sending data is a POST request. This data is hidden and is sent with the HTTP request too. Just because it's hidden doesn't mean it's all that more secure though. Anyways, many forms use POST data because it keeps sensitive information out of the url at least. So, if a form like below:
    Code:
    <form method="post">
    <input type="text" name="name"><input type="submit" value="Submit" />
    </form>
    were submitted, you could reference the value of the name textbox like so:
    Code:
    echo $_POST['name'];
    You can also reference these values through the $_REQUEST super global which is like the $_GET and $_POST superglobals except that it contains the contents of both of them.



    The second part of the expression is the operator, !=. It simply means, 'not equal to'. It compares the left expression to the right expression, and if they're not equal then the whole expression is true.

    The last part of the expression is called a string literal. "ds" is a value that's hard coded into the script, and is a string.


    And so the whole expression is checking to see whether the user submitted a value with the key of 'ob' through the POST data whose value is not equal to "ds". I hope that helped.

  5. #5
    Join Date
    Feb 2008
    Location
    Melbourne, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you Twey, djr33 and Jackbenimble4 for helping me understand this question that has been on my mind. I am going to read a tutorial on HTML POST and GET and try writing some PHP to get my head around all this. Thanks again!

  6. #6
    Join Date
    Feb 2008
    Location
    Melbourne, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Heaps

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
  •