title: if ($_server request_method == post ) don't work when form post
body: <p>I have a form for register and I used <code>securimage</code> captcha in my project. When I want echo something after <code>session_start();</code> like <code>print_r($_post)</code> result is <code>array()</code> but when I comment all <code>if</code> condition that's work, why? And when I submit my form to this page but for this condition don't submit just page refresh: </p>
  
  <pre><code>if ($_server request_method == post )//stop here don't go inside if condition
  </code></pre>
  
  <p>And this is my <code>register.php</code> page codes:</p>
  
  <pre><code>&lt;?PHP
      session_start();
  
  
  if ($_SERVER['REQUEST_METHOD'] == 'POST')
  {
      include_once dirname(__FILE__).'/process/dbconfig.php';
  
      $flag=true;
      echo"Asb";
      if(isset($_POST['captcha_code'])){
          include_once dirname(__FILE__) . '/captcha/securimage.php';
          $captcha = $_POST['captcha_code'];
          $image = new Securimage();
  
         echo $_POST['captcha_code'];
          if ($image-&gt;check($_POST['captcha_code']    ) == false) {
              $flag=false;
              $_SESSION['caperr']='Invalid captcha code';
              //$err='Invalid captcha code';
              header('Location: '.'reister.php');
          }
          //print_r($_SESSION['caperr']);
          if(isset($_POST['firstname']) &amp;&amp; isset($_POST['lastname']) &amp;&amp; isset($_POST['username']) &amp;&amp; isset($_POST['password1'])
              &amp;&amp; isset($_POST['password2']) &amp;&amp; isset($_POST['day']) &amp;&amp; isset($_POST['year']) &amp;&amp; isset($_POST['month'])
              &amp;&amp; isset($_POST['cell']) &amp;&amp; isset($_POST['agree']) &amp;&amp; isset($_POST['gen']) &amp;&amp; ($_POST['password1']==$_POST['password2']) &amp;&amp; $flag &amp;&amp; isset($_POST['agree'])){
  
              $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
              $sql = $conn-&gt;prepare('Insert into  users(firstname,lastname,username,password,birthday,gender,phone)values(:firstname,:lastname,:user,:pass,:birth,:gen,:phone)');
              $user=$_POST['username'];
              $firstname=$_POST['firstname'];
              $lastname=$_POST['lastname'];
              $pass=md5($_POST['password1']);
              $birth=$_POST['day'].'-'.$_POST['month'].'-'.$_POST['year'];
              $gen=$_POST['gen'];
              $phone=$_POST['cell'];
  
              $sql-&gt;bindParam(':user',$user,PDO::PARAM_STR,60);
              $sql-&gt;bindParam(':firstname',$firstname,PDO::PARAM_STR,50);
              $sql-&gt;bindParam(':lastname',$lastname,PDO::PARAM_STR,80);
              $sql-&gt;bindParam(':pass',$pass,PDO::PARAM_STR,60);
              $sql-&gt;bindParam(':gen',$gen,PDO::PARAM_BOOL);
              $sql-&gt;bindParam(':birth',$birth,PDO::PARAM_STR,10);
              $sql-&gt;bindParam(':phone',$phone,PDO::PARAM_STR,11);
              if($sql-&gt;execute()){
                  $_SESSION['success']='Your register is successful! ';
              }
          }
          else{
              if(!($_POST['password1']==$_POST['password2'])){
                  $_SESSION['errsubmitp']='Your passwords must same!';
              }
              else
                  $_SESSION['errsubmit']='Please fill all inputs!';
              $_SESSION['caperr']='Invalid captcha code';
  
              header('Location: '.'reister.php');
          }
      }
      else{
          echo "uuuuuuuuuuuuuuuuuuu";
          $_SESSION['captchafill']='Please Fill captcha code';
          header('Location: '.'reister.php');
  
      }
  }
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Register&lt;/title&gt;
      &lt;link href="content/css/main.css" rel="stylesheet" /&gt;   
      &lt;script src="content/js/jquery.js"&gt;&lt;/script&gt;
      &lt;script src="content/js/jBox.min.js"&gt;&lt;/script&gt;
      &lt;link href="content/css/jBox.css" rel="stylesheet" /&gt;
      &lt;script src="content/js/icheck.js"&gt;&lt;/script&gt;
      &lt;link href="content/css/minimal.css" rel="stylesheet" /&gt;
      &lt;script src="content/js/js.js"&gt;&lt;/script&gt;
      &lt;link href="content/css/chosen.min.css" rel="stylesheet" /&gt;
      &lt;script src="content/js/chosen.jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id="page"&gt;
          &lt;div id="head"&gt;
              &lt;h2&gt;Create your account&lt;/h2&gt;
          &lt;/div&gt;
  
          &lt;div id="content"&gt;
              &lt;div id="lefthalf"&gt;
                  &lt;span id="ajax_user" class="ajax_username"&gt;&lt;/span&gt;
  
                  &lt;?php if(isset($_SESSION['success'])) {?&gt;
                      &lt;div id="success" style="height: 60px;background-color: #53a642; text-align: center;"&gt;
                         &lt;div&gt; &lt;p style="  margin-left: 62px;  float: left;"&gt;&lt;?= $_SESSION['success']?&gt;&lt;/p&gt;
                             &lt;a href="login.php" style="text-decoration: none;color: #ff0;  margin-left: 7px;  margin-top: 15px;  float: left;"&gt;Login&lt;/a&gt;
                         &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;?php unset($_SESSION['success']);  }?&gt;
  
                  &lt;form action="register.php" method="post"&gt;
  
                      &lt;?php if(isset($_SESSION['errsubmit'])){ ?&gt;
                          &lt;span id="all"&gt;&lt;?=$_SESSION['errsubmit'];?&gt;&lt;/span&gt;
                      &lt;?php unset($_SESSION['errsubmit']); }?&gt;
  
                      &lt;div id="name"&gt;
                          &lt;label&gt;Name&lt;/label&gt;
                          &lt;input type="text" class="tooltip" name="firstname" placeholder="First" id="first" title="Please Enter Your FirstName!" style="margin-right:10px;" /&gt;
                          &lt;input type="text" class="tooltip" name="lastname" placeholder="Last" id="last" title="Please Enter Your LastName!" /&gt;
                          &lt;span id="firsterr"&gt;&lt;/span&gt;
                          &lt;span id="lasterr"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div id="username"&gt;
                          &lt;label&gt;Choose your username&lt;/label&gt;
                          &lt;input type="text" id="usernamef" name="username" class="tooltip" title="Please Enter Your UserName!" placeholder="Enter Username" /&gt;
                          &lt;span id="usernameerr" class="tooltip"&gt;&lt;/span&gt;
                          &lt;span id="valid"&gt;&lt;/span&gt;
                          &lt;label&gt;Create a password&lt;/label&gt;
                          &lt;input type="password" name="password1" id="pass" class="tooltip" title="Please Enter Your Password!" placeholder="Enter Your password" /&gt;
                          &lt;span id="passerr"&gt;&lt;/span&gt;
                          &lt;label&gt;Confirm your password&lt;/label&gt;
                          &lt;input type="password" id="conf" name="password2"  class="tooltip" title="Please Confirm Your Password!" placeholder="Confirm Your password" /&gt;
                          &lt;span id="conferr"&gt;&lt;/span&gt;
  
                          &lt;?php if(isset($_SESSION['errsubmitp'])){?&gt;
                               &lt;span id="confierr2"&gt;&lt;?=$_SESSION['errsubmitp'];?&gt;&lt;/span&gt;
                          &lt;?php unset($_SESSION['errsubmitp']); }?&gt;
  
                          &lt;span id="confierr"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div id="born"&gt;
                          &lt;label&gt;Birthday&lt;/label&gt;
                          &lt;div id="test"&gt;
                              &lt;select class="my_select_box chosen-select-no-results" tabindex="-1" id="month" data-placeholder="Month" name="month"&gt;
                                  &lt;option&gt;&lt;/option&gt;
                                  &lt;option value="1"&gt;January&lt;/option&gt;
                                  &lt;option value="2"&gt;February&lt;/option&gt;
                                  &lt;option value="3"&gt;March&lt;/option&gt;
                                  &lt;option value="4"&gt;April&lt;/option&gt;
                                  &lt;option value="5"&gt;May&lt;/option&gt;
                                  &lt;option value="6"&gt;June&lt;/option&gt;
                                  &lt;option value="7"&gt;July&lt;/option&gt;
                                  &lt;option value="8"&gt;August&lt;/option&gt;
                                  &lt;option value="9"&gt;September&lt;/option&gt;
                                  &lt;option value="10"&gt;October&lt;/option&gt;
                                  &lt;option value="11"&gt;November&lt;/option&gt;
                                  &lt;option value="12"&gt;December&lt;/option&gt;
                              &lt;/select&gt;
                          &lt;/div&gt;
  
                          &lt;input type="text" placeholder="Day" name="day" id="day" class="tooltip" title="Please Enter Your Born Day!" maxlength="2" onkeydown="prevent('#day');" /&gt;
  
                          &lt;input type="text" placeholder="Year" name="year" id="year" class="tooltip" title="Please Enter Your Born Year!" maxlength="4" onkeydown="prevent('#year');" /&gt;
  
                          &lt;span id="montherr"&gt;&lt;/span&gt;
                          &lt;span id="dayerr"&gt;&lt;/span&gt;
                          &lt;span id="yearerr"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div id="info"&gt;
                          &lt;label&gt;Gender&lt;/label&gt;
                          &lt;select id="gen" class="my_select_box chosen-select-no-results" name="gen"&gt;
                              &lt;option value="13"&gt;I am ...&lt;/option&gt;
                              &lt;option value="Male"&gt;Male&lt;/option&gt;
                              &lt;option value="Fmale"&gt;Fmale&lt;/option&gt;
                          &lt;/select&gt;
                          &lt;span id="gendererr"&gt;&lt;/span&gt;
                          &lt;label&gt;Mobile phone&lt;/label&gt;
                          &lt;div id="cell"&gt;
                              &lt;span&gt;+98&lt;/span&gt;
                              &lt;input type="tel" id="tel" name="cell" class="tooltip" title="Please Enter Your Mobile!" maxlength="11" onkeydown="prevent('#tel');" /&gt;
                          &lt;/div&gt;
                          &lt;span id="tellerr"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div id="captcha1"&gt;
                          &lt;img id="captcha" src="captcha/securimage_show.php" alt="Captcha Image"/&gt;
                          &lt;br/&gt;
                          &lt;input type="text" name="captcha_code" size="6" maxlength="6" id="captcha_code"/&gt;
                          &lt;br/&gt;
                          &lt;a href="#" onclick="document.getElementById('captcha').src='captcha/securimage_show.php?'+Math.random();return false;"&gt;AAA&lt;/a&gt;
                      &lt;/div&gt;
  
  
                      &lt;?php if(isset($_SESSION['captchafill'])){?&gt;
                          &lt;span id="chaperr1"&gt;&lt;?php $_SESSION['captchafill'];?&gt;&lt;/span&gt;
                      &lt;?php }unset($_SESSION['captchafill']);?&gt;
  
                      &lt;span id="chaperr"&gt;&lt;/span&gt;
                      &lt;div id="agree"&gt;
                          &lt;input type="checkbox" id="agg" name="agree"/&gt;
                          &lt;span style="margin-left:5px;"&gt;I agree to the term of services ...&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div id="register"&gt;
                          &lt;input type="submit" value="Register" id="reg" disabled="disabled" /&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>I see same question but any of theme has my question answer. Please help me to handle this problem.
  I echo  <code>var_dump($_SERVER)</code>  before  <code>if ($_SERVER['REQUEST_METHOD'] == 'post')</code> and this is my result:</p>
  
  <pre><code>array(45) { ["MIBDIRS"]=&gt; string(24) "C:/xampp/php/extras/mibs" ["MYSQL_HOME"]=&gt; string(16) "\xampp\mysql\bin" ["OPENSSL_CONF"]=&gt; string(31) "C:/xampp/apache/bin/openssl.cnf" ["PHP_PEAR_SYSCONF_DIR"]=&gt; string(10) "\xampp\php" ["PHPRC"]=&gt; string(10) "\xampp\php" ["TMP"]=&gt; string(10) "\xampp\tmp" ["HTTP_HOST"]=&gt; string(14) "localhost:8181" ["HTTP_CONNECTION"]=&gt; string(10) "keep-alive" ["CONTENT_LENGTH"]=&gt; string(3) "207" ["HTTP_CACHE_CONTROL"]=&gt; string(9) "max-age=0" ["HTTP_ACCEPT"]=&gt; string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" ["HTTP_ORIGIN"]=&gt; string(21) "http://localhost:8181" ["HTTP_USER_AGENT"]=&gt; string(113) "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36" ["CONTENT_TYPE"]=&gt; string(33) "application/x-www-form-urlencoded" ["HTTP_REFERER"]=&gt; string(36) "http://localhost:8181/a2/reister.php" ["HTTP_ACCEPT_ENCODING"]=&gt; string(13) "gzip, deflate" ["HTTP_ACCEPT_LANGUAGE"]=&gt; string(23) "en-US,en;q=0.8,fa;q=0.6" ["HTTP_COOKIE"]=&gt; string(36) "PHPSESSID=knkseus8v498m0p1au7q84lqd4" ["PATH"]=&gt; string(1170) "C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;E:\SoftWare\Programming soft\JaVa\android\adt-bundle-windows-x86_64-20131030\sdk\platform-tools;E:\SoftWare\Programming soft\JaVa\android\adt-bundle-windows-x86_64-20131030\sdk\tools;C:\Program Files (x86)\Java\jdk1.6.0_45\bin;C:\Program Files\nodejs\;C:\Users\Farshid\Downloads\Compressed\apache-ant-1.9.4\bin;C:\Program Files\nodejs;C:\Program Files (x86)\Java\jdk1.6.0_45\bin;C:\Users\Farshid\AppData\Local\Code\bin;C:\Users\Farshid\AppData\Roaming\npm;C:\Program Files (x86)\Git\bin" ["SystemRoot"]=&gt; string(10) "C:\Windows" ["COMSPEC"]=&gt; string(27) "C:\Windows\system32\cmd.exe" ["PATHEXT"]=&gt; string(53) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" ["WINDIR"]=&gt; string(10) "C:\Windows" ["SERVER_SIGNATURE"]=&gt; string(96) "
  Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3 Server at localhost Port 8181
  " ["SERVER_SOFTWARE"]=&gt; string(46) "Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3" ["SERVER_NAME"]=&gt; string(9) "localhost" ["SERVER_ADDR"]=&gt; string(3) "::1" ["SERVER_PORT"]=&gt; string(4) "8181" ["REMOTE_ADDR"]=&gt; string(3) "::1" ["DOCUMENT_ROOT"]=&gt; string(15) "C:/xampp/htdocs" ["REQUEST_SCHEME"]=&gt; string(4) "http" ["CONTEXT_PREFIX"]=&gt; string(0) "" ["CONTEXT_DOCUMENT_ROOT"]=&gt; string(15) "C:/xampp/htdocs" ["SERVER_ADMIN"]=&gt; string(20) "postmaster@localhost" ["SCRIPT_FILENAME"]=&gt; string(30) "C:/xampp/htdocs/a2/Reister.php" ["REMOTE_PORT"]=&gt; string(5) "24763" ["GATEWAY_INTERFACE"]=&gt; string(7) "CGI/1.1" ["SERVER_PROTOCOL"]=&gt; string(8) "HTTP/1.1" ["REQUEST_METHOD"]=&gt; string(4) "POST" ["QUERY_STRING"]=&gt; string(0) "" ["REQUEST_URI"]=&gt; string(15) "/a2/reister.php" ["SCRIPT_NAME"]=&gt; string(15) "/a2/reister.php" ["PHP_SELF"]=&gt; string(15) "/a2/reister.php" ["REQUEST_TIME_FLOAT"]=&gt; float(1433452977.521) ["REQUEST_TIME"]=&gt; int(1433452977) }
  </code></pre>
  
  <p><strong>Edit:</strong><br>
  <a href="https://goo.gl/uUQ9O8" rel="nofollow">This</a> my project link for download</p>