我正在使用php
代码来登录到一个网站, 我使用curl来做到这一点,但我有一个问题:(登录到特定的网站...当我使用这个代码,它不会登录(这意味着如果我发布了错误的密码或错误的用户名,它不会显示登录错误,我认为它不会发布我的数据?!?!?!?!我不知道,请查看代码的打击)使用curl登录到网站
<?php
$ch = curl_init();
$url = 'http://example.com/login.php';
$data = "css/style1.css";
curl_setopt($ch, CURLOPT_URL, $url.'/index.php');
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=something&password=something");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$answer = curl_exec($ch);
$answer = str_replace('href="','href="'.$url.'/',$answer);
echo $answer;
?>
我应该说我用这个代码在其他网站的URL,但它的工作原理,它显示了我的错误登录,但在这个网站它不工作.. ..
这里是我的网址HTML源登录(登录页面):
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>my url code</title>
<link rel="stylesheet" href="css/style1.css">
<!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<div id="header_outer">
</div>
<form method="post" action="" class="login">
<p>
<label for="login">Username: </label>
<input type="text" name="username" id="username" value="">
</p>
<p>
<label for="password">Password: </label>
<input type="password" name="password" id="password" value="">
</p>
<p class="login-submit">
<button type="submit" name="Login" class="login-button">Login</button>
</p>
<p class="forgot-password"><a href="forgot.php">Forgot your password?</a></p>
\t \t
</form>
</body>
</html>
启用'CURLOPT_VERBOSE'进行调试。 (不,没有人可以在没有具体的错误信息的情况下告诉你什么是错误的,或者知道示例站点如何处理登录[或阻止脚本访问]真的。双'/ index.php'可能是相关的,而且缺少提交按钮请求值。) – mario
in'CURLOPT_POSTFIELDS' **'** password **'的** p **缺失 – mmm
亲爱的马里奥CURLOPT_VERBOSE未定义常量 –