Php 如果($服务器请求\方法==post)不';我在邮局上班
我有一个注册表表单,我在项目中使用了Php 如果($服务器请求\方法==post)不';我在邮局上班,php,post,Php,Post,我有一个注册表表单,我在项目中使用了securimagecaptcha。当我想在session_start()之后回显某个内容时像print\r($\u post)结果是array()但是当我注释所有如果条件有效,为什么?当我将表单提交到此页面时,但在这种情况下,不要仅提交页面刷新: if ($_server request_method == post )//stop here don't go inside if condition 这是我的register.php页面代码: <?P
securimage
captcha。当我想在session_start()之后回显某个内容时代码>像print\r($\u post)
结果是array()
但是当我注释所有如果条件有效,为什么?当我将表单提交到此页面时,但在这种情况下,不要仅提交页面刷新:
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>
编辑:
用于下载的my project链接PHP字符串比较区分大小写。由于您有method=“post”
,您将在$\u服务器['REQUEST\u method']
中获得post
,并且post==post
为false
:
php > var_dump('POST' == 'post');
bool(false)
在IF之前,可以尝试回显您的$\u服务器['REQUEST\u METHOD']
变量
或者var\u dump($\u SERVER)
并检查此数组中的错误-可能您的服务器没有设置请求方法键
或者尝试:
if( count($_POST) ){/*....*/};
if($\u服务器请求\u方法==post)
← 这是你的密码吗??请尝试if($\u服务器['REQUEST\u METHOD']=='POST')
。我将'POST'改为小写,但不回显结果中的任何内容!!你也加上引号了吗?如果您看到一个空页面,PHP可能会因为解析错误而中止。检查服务器的错误日志,查看其中是否报告了任何错误。另外,添加行错误报告(E_ALL)代码>到PHP脚本的顶部。这是我的项目链接供下载和测试:我测试了它,但没有回应任何内容,所以要进行基本调试:var\u dump($\u SERVER['REQUEST\u METHOD'])
,看看你真正得到了什么。我在我的问题中添加了结果!我把结果加到问题上
if( count($_POST) ){/*....*/};