Order of execution between php and POST (html) -
i have read , understand answers regarding order of execution still unclear how post works since html command. if php executes before html, how php variables data post unless sent second file?
i realize if use $_server['php_self']
form sent in sort of recursive manner. part confuses me: ($_server["request_method"] == "post"
) how can line ever evaluate if post method executes after php?
i wouldn't mind using $_server['php_self']
because other piece makes sense but, if want use variables in mysql search , loading of subsequent form based on results.
obviously new , apologize if question seems simple i can these concepts clear in mind, sure able move forward.
let me explain how php works.
php preprocessor. means process http request and, after processing data in request, result sent browser.
that result http response, holds "headers" , "content".
the content see (an image, text, html, css, script, or binary files pdfs).
the headers set of values telling state of request. important headers content-type
tells size in bytes of content received, , status code, give result of operation. important because such values numbers different meanings like:
- 200 (good response)
- 500 , upper (server errors)
- 400 , upper (up 499, request errors),
- 300 399 mean redirections. 301 , 302 important because force browser redirect given url.
- many others 100 199, use them.
well... how php processes everything:
- your server (which supports php) receives http://a.request.to/a/specific.url.php
- the server tells target php file and, instead of returning it, "executes" it.
- the php script begins isolated execution (this means: execution of script totally independent of execution of other scripts -or other accesses same script- now, before, , in future). php script knows stuff php_self var in $_server, because holds uri of resource invoked.
- when scripts executing, sending (unless using special config or call) contents each
echo
command script has (basically; has other output sentences). - finally, content served client.
in way: need data passed, , need form beforehand.
that's get
comes us: it's content specific url. given url expected returned content "essentially same" after many subsequent requests. means: not alter server resource, , it's best candidate retrieve form (which printed php script) beforehand.
to process data via resource performs alteration in server use post method. post method affects server , not produce same output after subsequent requests.
both , post (i don't discuss put , delete here because they're not supported in forms) should return content or return http response justifying there's no content (like 201, 204, 301, 302, or error code). so, when visit normal page www.facebook.com resource (the displayed page) , when send data login form post data server (the server sessions , caches altered).
so order is: (get) resource (which provides "tool" send data back), display resource (the browser builds in browser), , send data (post) (you populate form , press submit button).
so execute twice same script (one get, 1 post).
a script issue:
<?php //code before line executes in first , second access if ($_server["request_method"] == "post") { //code here executes when send data pressing submit button } else { //code here executes when access url via link, address bar, or javascript url change methods } //code after line executes in first , second access
Comments
Post a Comment