I have a form(myform.php) on Server A that can only be accessed after attaining the correct session cookie from logging in from the log in page(login.php). So naturally the form can only be submitted if I am logged in.
And now, is it possible from Server B, to have a script to log in through login.php to attain the session cookie on the server and then do a submit in the myform.php?
So in another words, I need Server B to act as me logging into login.php and submitting the form on Server A.
Yes...Ofcourse, it's Possible.
Try using PHP CURL
Try to get some idea from the following code and try to implement it as per your need
PHP Code:
<?php
$url ="http://www.yoursite.com/login.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_POSTFIELDS, "current_form=loginForm&username=yourName&password=Unknown");
ob_start();
curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL,"http://www.yoursite.com/myform.php");
$result = curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
Bookmarks