php - if ($_server request_method == post ) don't work when form post -


i have form register , used securimage captcha in project. when want echo after session_start(); print_r($_post) result array() when comment if condition that's work, why? , when submit form page condition don't submit page refresh:

if ($_server request_method == post )//stop here don't go inside if condition 

and register.php page codes:

<?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->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']) && isset($_post['lastname']) && isset($_post['username']) && isset($_post['password1'])             && isset($_post['password2']) && isset($_post['day']) && isset($_post['year']) && isset($_post['month'])             && isset($_post['cell']) && isset($_post['agree']) && isset($_post['gen']) && ($_post['password1']==$_post['password2']) && $flag && isset($_post['agree'])){              $conn = new pdo("mysql:host=$host;dbname=$dbname", $username, $password);             $sql = $conn->prepare('insert  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->bindparam(':user',$user,pdo::param_str,60);             $sql->bindparam(':firstname',$firstname,pdo::param_str,50);             $sql->bindparam(':lastname',$lastname,pdo::param_str,80);             $sql->bindparam(':pass',$pass,pdo::param_str,60);             $sql->bindparam(':gen',$gen,pdo::param_bool);             $sql->bindparam(':birth',$birth,pdo::param_str,10);             $sql->bindparam(':phone',$phone,pdo::param_str,11);             if($sql->execute()){                 $_session['success']='your register successful! ';             }         }         else{             if(!($_post['password1']==$_post['password2'])){                 $_session['errsubmitp']='your passwords must same!';             }             else                 $_session['errsubmit']='please fill inputs!';             $_session['caperr']='invalid captcha code';              header('location: '.'reister.php');         }     }     else{         echo "uuuuuuuuuuuuuuuuuuu";         $_session['captchafill']='please fill captcha code';         header('location: '.'reister.php');      } } ?>  <html> <head>     <title>register</title>     <link href="content/css/main.css" rel="stylesheet" />        <script src="content/js/jquery.js"></script>     <script src="content/js/jbox.min.js"></script>     <link href="content/css/jbox.css" rel="stylesheet" />     <script src="content/js/icheck.js"></script>     <link href="content/css/minimal.css" rel="stylesheet" />     <script src="content/js/js.js"></script>     <link href="content/css/chosen.min.css" rel="stylesheet" />     <script src="content/js/chosen.jquery.min.js"></script>  </head>  <body>     <div id="page">         <div id="head">             <h2>create account</h2>         </div>          <div id="content">             <div id="lefthalf">                 <span id="ajax_user" class="ajax_username"></span>                  <?php if(isset($_session['success'])) {?>                     <div id="success" style="height: 60px;background-color: #53a642; text-align: center;">                        <div> <p style="  margin-left: 62px;  float: left;"><?= $_session['success']?></p>                            <a href="login.php" style="text-decoration: none;color: #ff0;  margin-left: 7px;  margin-top: 15px;  float: left;">login</a>                        </div>                     </div>                 <?php unset($_session['success']);  }?>                  <form action="register.php" method="post">                      <?php if(isset($_session['errsubmit'])){ ?>                         <span id="all"><?=$_session['errsubmit'];?></span>                     <?php unset($_session['errsubmit']); }?>                      <div id="name">                         <label>name</label>                         <input type="text" class="tooltip" name="firstname" placeholder="first" id="first" title="please enter firstname!" style="margin-right:10px;" />                         <input type="text" class="tooltip" name="lastname" placeholder="last" id="last" title="please enter lastname!" />                         <span id="firsterr"></span>                         <span id="lasterr"></span>                     </div>                     <div id="username">                         <label>choose username</label>                         <input type="text" id="usernamef" name="username" class="tooltip" title="please enter username!" placeholder="enter username" />                         <span id="usernameerr" class="tooltip"></span>                         <span id="valid"></span>                         <label>create password</label>                         <input type="password" name="password1" id="pass" class="tooltip" title="please enter password!" placeholder="enter password" />                         <span id="passerr"></span>                         <label>confirm password</label>                         <input type="password" id="conf" name="password2"  class="tooltip" title="please confirm password!" placeholder="confirm password" />                         <span id="conferr"></span>                          <?php if(isset($_session['errsubmitp'])){?>                              <span id="confierr2"><?=$_session['errsubmitp'];?></span>                         <?php unset($_session['errsubmitp']); }?>                          <span id="confierr"></span>                     </div>                     <div id="born">                         <label>birthday</label>                         <div id="test">                             <select class="my_select_box chosen-select-no-results" tabindex="-1" id="month" data-placeholder="month" name="month">                                 <option></option>                                 <option value="1">january</option>                                 <option value="2">february</option>                                 <option value="3">march</option>                                 <option value="4">april</option>                                 <option value="5">may</option>                                 <option value="6">june</option>                                 <option value="7">july</option>                                 <option value="8">august</option>                                 <option value="9">september</option>                                 <option value="10">october</option>                                 <option value="11">november</option>                                 <option value="12">december</option>                             </select>                         </div>                          <input type="text" placeholder="day" name="day" id="day" class="tooltip" title="please enter born day!" maxlength="2" onkeydown="prevent('#day');" />                          <input type="text" placeholder="year" name="year" id="year" class="tooltip" title="please enter born year!" maxlength="4" onkeydown="prevent('#year');" />                          <span id="montherr"></span>                         <span id="dayerr"></span>                         <span id="yearerr"></span>                     </div>                     <div id="info">                         <label>gender</label>                         <select id="gen" class="my_select_box chosen-select-no-results" name="gen">                             <option value="13">i ...</option>                             <option value="male">male</option>                             <option value="fmale">fmale</option>                         </select>                         <span id="gendererr"></span>                         <label>mobile phone</label>                         <div id="cell">                             <span>+98</span>                             <input type="tel" id="tel" name="cell" class="tooltip" title="please enter mobile!" maxlength="11" onkeydown="prevent('#tel');" />                         </div>                         <span id="tellerr"></span>                     </div>                     <div id="captcha1">                         <img id="captcha" src="captcha/securimage_show.php" alt="captcha image"/>                         <br/>                         <input type="text" name="captcha_code" size="6" maxlength="6" id="captcha_code"/>                         <br/>                         <a href="#" onclick="document.getelementbyid('captcha').src='captcha/securimage_show.php?'+math.random();return false;">aaa</a>                     </div>                       <?php if(isset($_session['captchafill'])){?>                         <span id="chaperr1"><?php $_session['captchafill'];?></span>                     <?php }unset($_session['captchafill']);?>                      <span id="chaperr"></span>                     <div id="agree">                         <input type="checkbox" id="agg" name="agree"/>                         <span style="margin-left:5px;">i agree term of services ...</span>                     </div>                     <div id="register">                         <input type="submit" value="register" id="reg" disabled="disabled" />                     </div>                 </form>             </div>         </div>      </div> </body>  </html> 

i see same question of theme has question answer. please me handle problem. echo var_dump($_server) before if ($_server['request_method'] == 'post') , result:

array(45) { ["mibdirs"]=> string(24) "c:/xampp/php/extras/mibs" ["mysql_home"]=> string(16) "\xampp\mysql\bin" ["openssl_conf"]=> string(31) "c:/xampp/apache/bin/openssl.cnf" ["php_pear_sysconf_dir"]=> string(10) "\xampp\php" ["phprc"]=> string(10) "\xampp\php" ["tmp"]=> string(10) "\xampp\tmp" ["http_host"]=> string(14) "localhost:8181" ["http_connection"]=> string(10) "keep-alive" ["content_length"]=> string(3) "207" ["http_cache_control"]=> string(9) "max-age=0" ["http_accept"]=> string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" ["http_origin"]=> string(21) "http://localhost:8181" ["http_user_agent"]=> string(113) "mozilla/5.0 (windows nt 6.3; win64; x64) applewebkit/537.36 (khtml, gecko) chrome/43.0.2357.81 safari/537.36" ["content_type"]=> string(33) "application/x-www-form-urlencoded" ["http_referer"]=> string(36) "http://localhost:8181/a2/reister.php" ["http_accept_encoding"]=> string(13) "gzip, deflate" ["http_accept_language"]=> string(23) "en-us,en;q=0.8,fa;q=0.6" ["http_cookie"]=> string(36) "phpsessid=knkseus8v498m0p1au7q84lqd4" ["path"]=> 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"]=> string(10) "c:\windows" ["comspec"]=> string(27) "c:\windows\system32\cmd.exe" ["pathext"]=> string(53) ".com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc" ["windir"]=> string(10) "c:\windows" ["server_signature"]=> string(96) " apache/2.4.10 (win32) openssl/1.0.1i php/5.6.3 server @ localhost port 8181 " ["server_software"]=> string(46) "apache/2.4.10 (win32) openssl/1.0.1i php/5.6.3" ["server_name"]=> string(9) "localhost" ["server_addr"]=> string(3) "::1" ["server_port"]=> string(4) "8181" ["remote_addr"]=> string(3) "::1" ["document_root"]=> string(15) "c:/xampp/htdocs" ["request_scheme"]=> string(4) "http" ["context_prefix"]=> string(0) "" ["context_document_root"]=> string(15) "c:/xampp/htdocs" ["server_admin"]=> string(20) "postmaster@localhost" ["script_filename"]=> string(30) "c:/xampp/htdocs/a2/reister.php" ["remote_port"]=> string(5) "24763" ["gateway_interface"]=> string(7) "cgi/1.1" ["server_protocol"]=> string(8) "http/1.1" ["request_method"]=> string(4) "post" ["query_string"]=> string(0) "" ["request_uri"]=> string(15) "/a2/reister.php" ["script_name"]=> string(15) "/a2/reister.php" ["php_self"]=> string(15) "/a2/reister.php" ["request_time_float"]=> float(1433452977.521) ["request_time"]=> int(1433452977) } 

edit:
this project link download

maybe try echo $_server['request_method'] variable before if

or var_dump($_server) , check what's wrong in array - maybe server don't set request_method key

or try:

if( count($_post) ){/*....*/}; 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -