If I am testing whether my HTML form (with method post) has been submitted (vs a fresh page load), is there any benefit to using  if( $_SERVER["REQUEST_METHOD"] == "POST" ) { }  as opposed to  if( $_POST) { }.   Let's assume that either way, after this check I am checking for isset( $_POST['my_var'] ).
111364
Some guy called one of my Snipplr submissions "crap" because I used if ($_SERVER['REQUEST_METHOD'] == 'POST') instead of if ($_POST)  Checking the request method seems more correct to me because that's what I really want to do. Is there some operational difference between the two or is this just a code clarity issue?
73078
Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form? The submit button is not there. I am using a custom div instead of that.
8265
I have now seen 2 methods for determining if an argument has been passed to a JavaScript function. I'm wondering if one method is better than the other or if one is just bad to use?   function Test(argument1, argument2) {       if (Test.arguments.length == 1) argument2 = 'blah';        alert(argument2);  }   Test('test');   Or   function Test(argument1, argument2) {       argument2 = argument2 || 'blah';        alert(argument2);  }   Test('test');   As far as I can tell, they both result in the same thing, but I've only used the first one before in production.  Another Option as mentioned by :  function Test(argument1, argument2) {     if(argument2 === null) {         argument2 = 'blah';     }      alert(argument2); }   As per Juan's comment, it would be better to change Tom's suggestion to:  function Test(argument1, argument2) {     if(argument2 === undefined) {         argument2 = 'blah';     }      alert(argument2); }
30534
I am having a form page called Test Form with this form :  &lt;div id="container"&gt; &lt;form action="wp-content/themes/max-magazine/TestForm.php" method="post" name="myForm"&gt; User &lt;input type="text"  name="uname" /&gt; Email  &lt;input id="email" type="text" name="uemail" /&gt; Password  &lt;input type="password"  name="upass" /&gt; &lt;input type="submit" value="Submit" /&gt;&lt;/form&gt; &lt;/div&gt;   And in backend am having a php file named TestForm.php  &lt;?php  function create_account(){ $user = 'AccountID'; $pass = 'AccountPassword'; $email = 'email@domain.com'; if ( !username_exists( $user )  &amp;&amp; !email_exists( $email ) ) {     $user_id = wp_create_user( $user, $pass, $email );     $user = new WP_User( $user_id );     $user-&gt;set_role( 'contributor' ); }  } add_action('init','create_account'); ?&gt;   Now if this function is defined in function.php then it works fine and create the user but same function in TestForm.php does not work. Please help  Also I will be fetching data from form like this :  &lt;?php $user = $_POST['uname']; $pass = $_POST['upass']; $email = $_POST['uemail']; ?&gt;
81297
If I hit a page which calls session_start(), how long would I have to wait before I get a new session ID when I refresh the page?
105097
I'm wondering how SO is able to display the "New answers have been posted" message when I'm typing an answer for a question. Does my browser send an AJAX request to the SO servers, or does SO send a trigger back to my browser?
1813
I have two submit buttons in a form. How do I determine which one was hit serverside?
87186
For the following pretty straightforward task: query a list of products from a DB and present it on a webpage, consider 2 setups:  Setup1: PHP script queries. All content is built on the server and the entire page is served back to the client.  Setup2: Static HTML "page skeleton" requesting content using AJAX. Received content is parsed on the client side using Javascript and rendered using innerHTML or similar.  Of course the second setup only makes sense when you have pages, categories and tags for the client user to choose from.  I need to compare these two, at least by means of:   time it will take content to be served user experience (setup1 is delivered as a whole, setup2 is delivered in "two parts") scalability - how do the setups compare when I have 100,000 queries daily   Any thoughts on the issue will be much appreciated.
73
If user input is inserted without modification into an SQL query, then the application becomes vulnerable to , like in the following example:  $unsafe_variable = $_POST['user_input'];   mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')");   That's because the user can input something like value'); DROP TABLE table;--, and the query becomes:  INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--')   What can be done to prevent this from happening?
61570
I would like to know what would be the best way to do unit testing of a servlet.   Testing internal methods is not a problem as long as they don't refer to the servlet context, but what about testing the doGet/doPost methods as well as the internal method that refer to the context or make use of session parameters?  Is there a way to do this simply using classical tools such as JUnit, or preferrably TestNG? Did I need to embed a tomcat server or something like that?
7415
I'm familiar with some of the basics, but what I would like to know more about is when and why error handling (including throwing exceptions) should be used in PHP, especially on a live site or web app. Is it something that can be overused and if so, what does overuse look like? Are there cases where it shouldn't be used? Also, what are some of the common security concerns in regard to error handling?
121410
Hi im quite new to PHP, i have created a form for very large csv files to be uploaded to my server. Some one mentioned to me that the browser can time out due to the uploading file being to big, is this true? and if so, can it be prevented?  Thanks for your help!
79018
Is it possible to detect the HTTP request method (e.g. GET or POST) of a page from JavaScript?  If so, how?
27078
I noticed for a while now the following syntax in some of our code:  if( NULL == var){    //... }   or  if( 0 == var){   //... }   and similar things.  Can someone please explain why did the person who wrote this choose this notation instead of the common var == 0 way)?  Is it a matter of style, or does it somehow affect performance?
49597
This is a double question: The correct answer will go to "How you do it in PHP" explaining if there is any advantage goes also counts if possible.  I'm just curious because I really don't know and I see it a lot in webpages.  Edit: I don't know the technical name, but for example here on Stackoverflow: "http://stackoverflow.com/posts/edit/522452" is what I mean as "folders" (a term previously used in the title of the question).
107747
Please bear with me because I am new to utilizing Wordpress PHP this way. I have the following script:  &lt;div id="content"&gt; &lt;?php     // check if the repeater field has rows of data     if( have_rows('repeat_field') ):         $i = 0;          // loop through the rows of data         while ( have_rows('repeat_field') ) : the_row();             $i++;              // display a sub field value             if (!empty(get_sub_field('feature_image_post'))) {                  echo '&lt;a href="';                 the_sub_field('restaurant_article_link');                  echo '"&gt;';             }              if( $i &gt;= 78 ) {                 break;             }                     endwhile;     else :         // no rows found     endif;     ?&gt;     &lt;/div&gt;     &lt;div id="loading-image" style="display: none;"&gt;&lt;/div&gt;     &lt;div id="part2"&gt;&lt;/div&gt;     &lt;script&gt;          var w = $(window);         window.onscroll = function(ev) {             if ($(document).height() - w.height() == w.scrollTop()) {                  $('#loading-image').show();                 $.ajax({                     url: "&lt;?php echo get_stylesheet_directory_uri();?&gt;/post-2.php",                     cache: false,                     success: function(result){                       $("#part2").html(result);                     },                     complete: function(){                       $('#loading-image').hide();                     }                 });             }         };     &lt;/script&gt;   The the Php page that I am trying to load pretty much contains the same code . It just stops after loading 200 fields.   &lt;?php     // check if the repeater field has rows of data     if( have_rows('repeat_field') ):         $i = 0;         // loop through the rows of data         while ( have_rows('repeat_field') ) : the_row();             $i++;             // display a sub field value             if (!empty(get_sub_field('feature_image_post'))) {                 echo '&lt;a href="';                 the_sub_field('restaurant_article_link');                  echo '"&gt;';             }              if( $i &gt;= 200 ){               break;             }                      endwhile;     else :         // no rows found     endif; ?&gt;   I don't know why the php page (post-2.php) is not loading. The strange thing is that when I replace &lt;?php echo get_stylesheet_directory_uri();?&gt;/post-2.php with a test html page &lt;?php echo get_stylesheet_directory_uri();?&gt;/test.html The test page (test.html) loads.  I have to say that I looked on in my console using the console tab of my browser added console.log(); to view any errors and I'm not getting any errors. I also looked in my networked tag to ensure that post-2.php loaded properly and I'm not getting errors. My goal is to find out why my PHP page isn't loading  ***** Update ***** I'm being told to use $post_id but I've never used it. Does anyone have a working example of this? Would it be similar to if( have_rows('repeat_field', $post_id) ): or if( have_rows('repeat_field', 55612) ): ?
28523
Here's a PHP example of mine. Can anyone find a shorter/easier way to do this?  &lt;? foreach($posts as $post){?&gt;     &lt;div class="&lt;?=($c++%2==1)?‘odd’:NULL?&gt;"&gt;         &lt;?=$post?&gt;     &lt;/div&gt; &lt;? }?&gt;  &lt;style&gt;     .odd{background-color:red;} &lt;/style&gt;   Examples in other languages would be fun to see as well.