我正在尝试发布方法来发送 var 检查某些条件
如果用户已登录,则显示按钮并单击将数据发布到,ind.php
如果未登录则显示标签代码:
<?php
session_start();
$appId = 'fgf';
$appSecret = ''; // Facebook App Secret
$return_url = 'amazonaws.com/'; //path to script folder
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ThenWat</title>
<script>
function showUser(form, e) {
e.preventDefault();
e.returnValue=false;
var sent = form.elements['sent'].value;
alert(sent);
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(e) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open(form.method, form.action, true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(sent);
}
</script>
</head>
<body style="height: 560px">
<?php
if (isset($_SESSION['logged_in'])) {
?>
<form action="ind.php" method="POST" onsubmit="showUser(this, event)">
<pre>
<label>Enter the sentence: <input type="text" name="sent"></label><br/>
</pre>
<input type="submit" class="submit" name="insert" value="submit"/>
</form>
<?php
}
?>
<?php
if (!isset($_SESSION['logged_in'])) {
?>
<label>not logged in </label>
<?php
}
?>
<div id="txtHint"> </div>
</body>
</html>
ind.php
<html>
<body>
<?php
$s=$_POST['sent'];
echo $s;
?>
</body>
</html>
总是说未登录,如果我删除条件数据不会发布在 ind.php 上。错误:Undefined index: sent in /opt/lampp/htdocs/a/FB/ec2/ind.php on line 5