这是我的索引
<body>
<form id="form1" method="post" name="entrar" action="procesar.php">
<p>Usuario
<label for="username">:</label>
<input type="text" name="username" id="username">
</p>
<p>
<label for="pass">Clave:</label>
<input type="password" name="pass" id="pass">
</p>
<p>
<input type="submit" name="entrar" id="button" value="Enviar">
</p>
</form>
</body>
当检查值username并传递
时,这是procesa.php的代码<?php
if($_POST['entrar']){
$user = $_POST['username'];
$pass = $_POST['pass'];
if($user == 'gato' && $pass == 'gato'){
setcookie('control','1234',time()+30000,'/','www.onlinelatino.org');
header("Location: sitio.php");
}
else{
header("Location: error.php");
}
}
else{
echo "error inclucion no valida";
}
?>
稍后去这里
<!doctype html>
<html>
<head><title>Welcome</title></head>
<body>
<?php
$control = $_COOKIE['control'];
if($control == 1234){
?>
<h1>Hola mundo</h1>
<h2>Como estas</h2>
<?php
}
else{
echo "No estas logado";
}
?>
</body>
</html>
这项工作很好但我想在机器人这是一个代码时访问网站
<?php
$parametros_post = 'username='.urlencode("gato").'&pass='.urlencode("gato").'&entrar'.urlencode("Enviar");
$cookie_file = "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.onlinelatino.org/curl/procesar.php");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01 Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es, en"));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parametros_post);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
echo $result;
echo $error;
?>
但是没有用cookie启动sesion 只说说这个“错误包含无效”这是在procesar.php上 这个例子的链接就是这个 http://www.onlinelatino.org/curl/index.html 机器人就是这个 http://www.onlinelatino.org/curl/bot.php
我不知道什么时候出错
答案 0 :(得分:0)
'&entrar'.urlencode("Enviar")
你错过了一个=
'&entrar='.urlencode("Enviar")