PDA

View Full Version : if ($_POST[op]!="ds"



iaturner
02-18-2008, 09:28 AM
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

Twey
02-18-2008, 09:33 AM
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.

djr33
02-18-2008, 11:40 AM
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.

jackbenimble4
02-18-2008, 03:01 PM
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:

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:

<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:

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.

iaturner
02-19-2008, 10:49 AM
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!

iaturner
02-19-2008, 11:01 AM
Thanks Heaps