2013-07-09 4 views
1

Я стараюсь сделать вход с существующими учетными записями с другого сайта. [. Учетные записи сделаны на Zwinky]Curl Войти с существующими учетными записями

РНР код выглядит следующим образом:

<?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> 

Но я не знаю, его не показывая никаких сообщений об ошибках, если Я использую учетную запись, которая не существует. Я также хочу сохранить введенную информацию в текстовый документ. Кто-нибудь получил какую-то информацию? Или советы?

Большое спасибо

+0

сайт, который позволяет вам зарегистрироваться через простой GET, - это ... просто глупо. –

+0

Хм мог бы кто-нибудь помочь? – user2452165

ответ

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); 
} 
Смежные вопросы