1

我尝试使用另一个站点的现有帐户登录。[帐户是在 zwinky 上制作的。]

PHP 代码如下所示:

<?php
$Luser = "swagg_ma_blue";
$Lpass = "mypassword";
$L_info = "http://registration.zwinky.com/registration/loginAjax.jhtml?        
username=".$Luser."&password=".$Lpass;
$zwinky_login_file = file_get_contents($L_info, true);
if (substr($zwinky_login_file, 12, 1) == "u"){ $message = "Blank username!"; }
if (substr($zwinky_login_file, 12, 1) == "p"){ $message = "Blank password!"; }
if (substr($zwinky_login_file, 12, 1) == "w"){ $message = "Wrong user/pass    combination!"; }
if (substr($zwinky_login_file, 12, 1) == "s"){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $L_info);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "sessions/".$Luser);
curl_setopt($ch, CURLOPT_COOKIEJAR, "sessions/".$Luser);
$response = curl_exec($ch);
curl_close($ch);
$_SESSION['username'] = $Luser;
$_SESSION['password'] = $Lpass;
header('Location: ../index.html');
die;
}
?>

Html 代码如下:

<!DOCTYPE html>
<html>
<head>
<title>Sign In</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>

<!-- Warning -->
<div class="alert alert-info">
    Please sign in with your Zwinky account!
</div>  

<div class="container">
    <form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" id="Luser" class="input-block-level" placeholder="ZwinkyUsername">
<input type="password" id="Lpass" class="input-block-level" placeholder="ZwinkyPassword">
<button class="btn btn-large btn-primary" type="submit">Sign in</button>
</form>
</div>
</div>
</body>
</html>

但我不知道,如果我使用不存在的帐户,它不会显示任何错误消息。我还想将输入的信息保存到文本文档中。有人知道一些信息吗?还是提示?

非常感谢

4

1 回答 1

1

在 ImpressPages 上,我就是这样做的。它没有被您的脚本采用。您可能需要更改 POSTFIELDS 变量。用 GET 替换它们:

//initial request with login data

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/login.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_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=XXXXX&password=XXXXX");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-name');  //could be empty, but cause problems on some hosts
curl_setopt($ch, CURLOPT_COOKIEFILE, '/var/www/ip4.x/file/tmp');  //could be empty, but cause problems on some hosts
$answer = curl_exec($ch);
if (curl_error($ch)) {
    echo curl_error($ch);
}

//another request preserving the session

curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/profile');
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$answer = curl_exec($ch);
if (curl_error($ch)) {
    echo curl_error($ch);
}
于 2014-03-06T07:44:13.587 回答