Jump to content

remote login, stay logged in


blitz219

Recommended Posts

i have a problem logging into a remote website

 

this code works to grab data from website but i want to be able to redicrect to the members section still logged in with a session id.

 

<?php

error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));

// INIT CURL

$ch = curl_init();

 

// SET URL FOR THE POST FORM LOGIN

curl_setopt($ch, CURLOPT_URL, 'www.remotesite.com/login.php');

 

// ENABLE HTTP POST

curl_setopt ($ch, CURLOPT_POST, 1);

 

$user = 'username';

$pass = 'password';

 

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD

curl_setopt ($ch, CURLOPT_POSTFIELDS, "login_username=$user&login_password=$pass");

 

// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES

curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

 

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL

# not to print out the results of its query.

# Instead, it will return the results as a string return value

# from curl_exec() instead of the usual true/false.

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

 

// EXECUTE 1st REQUEST (FORM LOGIN)

$store = curl_exec ($ch);

 

// SET FILE TO DOWNLOAD

curl_setopt($ch, CURLOPT_URL, 'www.remotesite.com/file.php');

 

// EXECUTE 2nd REQUEST (FILE DOWNLOAD)

$content = curl_exec ($ch);

 

// CLOSE CURL

curl_close ($ch);

Link to comment
https://forums.phpfreaks.com/topic/186727-remote-login-stay-logged-in/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.