if($ _server request_method == post)在表单发布时不起作用

时间:2015-06-03 21:42:02

标签: php post

我有一个注册表单,我在项目中使用了securimage验证码。当我希望在session_start(); print_r($_post)结果为array()之后回复某事时,但当我评论所有if条件时,为什么?当我将表单提交到此页面时,但是对于这种情况,请不要仅提交页面刷新:

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

这是我的register.php页码:

<?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 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->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 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');

    }
}
?>

<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 your 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 Your FirstName!" style="margin-right:10px;" />
                        <input type="text" class="tooltip" name="lastname" placeholder="Last" id="last" title="Please Enter Your LastName!" />
                        <span id="firsterr"></span>
                        <span id="lasterr"></span>
                    </div>
                    <div id="username">
                        <label>Choose your username</label>
                        <input type="text" id="usernamef" name="username" class="tooltip" title="Please Enter Your UserName!" placeholder="Enter Username" />
                        <span id="usernameerr" class="tooltip"></span>
                        <span id="valid"></span>
                        <label>Create a password</label>
                        <input type="password" name="password1" id="pass" class="tooltip" title="Please Enter Your Password!" placeholder="Enter Your password" />
                        <span id="passerr"></span>
                        <label>Confirm your password</label>
                        <input type="password" id="conf" name="password2"  class="tooltip" title="Please Confirm Your Password!" placeholder="Confirm Your 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 Your Born Day!" maxlength="2" onkeydown="prevent('#day');" />

                        <input type="text" placeholder="Year" name="year" id="year" class="tooltip" title="Please Enter Your 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 am ...</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 Your 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 to the term of services ...</span>
                    </div>
                    <div id="register">
                        <input type="submit" value="Register" id="reg" disabled="disabled" />
                    </div>
                </form>
            </div>
        </div>

    </div>
</body>

</html>

我看到同样的问题,但任何主题都有我的问题答案。请帮我处理这个问题。 我在var_dump($_SERVER)之前回复if ($_SERVER['REQUEST_METHOD'] == 'post'),这是我的结果:

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, like 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 at 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) }

修改
This我的项目链接供下载

2 个答案:

答案 0 :(得分:1)

也许在IF

之前尝试回复你$_SERVER['REQUEST_METHOD']变量

var_dump($_SERVER)并查看此阵列中的错误 - 也许您的服务器未设置REQUEST_METHOD键

或尝试:

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

答案 1 :(得分:0)

PHP字符串比较区分大小写。由于您有method="post",因此post中的$_SERVER['REQUEST_METHOD']POST == post falsephp > var_dump('POST' == 'post'); bool(false)

UIDocumentInteractionController