0

Hey there everybody!:)

I need some help to make a piece of code i made work.

It current gets the login process right, however it doesnt save the cookies right:(

(AC-Web.org is running vBulletin 4.2)

<?php
$sites = array(
array(
    "url_login" => "http://www.ac-web.org/forums/login.php?do=login",
    "url_front" => "http://www.ac-web.org/forums/",
    "user_field" => "vb_login_username",
    "pass_field" => "vb_login_md5password",
    "remember_field" => "cookieuser",
    "password" => "md5",
    "post_data" => "do=login&url=forum.php&",
)
);

$users = array(
array(
    "user" => "blyitgen",
    "pass" => "**********",
),
);

if(!isset($_GET['user'])) {
    die("Please make a request.");
}
if(!isset($_GET['site'])) {
    die("Please choose a service");
}

$requestedSite = $_GET['site'] - 1;
$requestedUser = $_GET['user'] - 1;

$site_url = $sites[$requestedSite]['url_login'];
$site_front = $sites[$requestedSite]['url_front'];
$user_field = $sites[$requestedSite]['user_field'];
$pass_field = $sites[$requestedSite]['pass_field'];
$remember_field = $sites[$requestedSite]['remember_field'];
$special_pass = $sites[$requestedSite]['password'];
$post_data = $sites[$requestedSite]['post_data'];

$username = $users[$requestedUser]['user'];

switch($special_pass) {
    case "md5":
    $password = md5($users[$requestedUser]['pass']);
    break;
    case "sha1":
    $password = sha1($users[$requestedUser]['pass']);
    break;
    default:
    $password = $users[$requestedUser]['pass'];
}

$data = array($user_field => $username, $pass_field => $password, $remember_field => '0');

$data = $post_data . "$user_field=$username&$pass_field=$password&$remember_field=1";

//die($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $site_url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/codecall_$username.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/codecall_$username.txt");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 7);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$exec = curl_exec($ch);

curl_close($ch);

$pos = strpos($exec, "Thank you for logging in");
if($pos === FALSE) {
    die("Could not log you in!");
}
else {

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.ac-web.org/forums/content.php");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/codecall_$username.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/codecall_$username.txt");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 7);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$exec = curl_exec($ch);

curl_close($ch);

echo $exec;
}
?>

the code is designed to work with multiple users and sites.

I am doing this for the site itself, as they are making an application which i sadly cant say anything more about, so no malicious script here.

Would help me very much if anybody could help!:)

2
Contributors
1
Reply
4
Views
4 Years
Discussion Span
Last Post by LastMitch
0

@Weliaz

It current gets the login process right, however it doesnt save the cookies right:(

I'm not sure if you find an answer for your issue yet.

You need to create a pregmatch() regex and plus does codecall_$username.txt exist at all?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.