snapper64 Posted August 20, 2006 Share Posted August 20, 2006 Hi Guys,I need to create a script that logs me in to http://tracks.tra.in/login. So i visit www.mydomain.com/tracks.php, it logs me in using the data stored in the php file and then sends me to http://tracks.tra.in/.I have got this so far:[code]<?php$cookieJar = \\\\\\\"cookie\\\\\\\";//this should be set to whatever file on the computer you want to save and retrieve cookies to/from$userAgent = \\\\\\\"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5\\\\\\\";$postData = \\\\\\\"user_login=gwbush&user_password=password\\\\\\\";$url_login = \\\\\\\"http://tracks.tra.in/login\\\\\\\";$url_view = \\\\\\\'http://tracks.tra.in/\\\\\\\';$ch = curl_init(); //creates and initializes a curl sessioncurl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar); //sets the file to save cookies in after recieving them from the pagecurl_setopt($ch, CURLOPT_COOKIEFILE, $cookieJar); //sets file to take cookies from to give to the site if neededcurl_setopt($ch, CURLOPT_USERAGENT, $userAgent); //sets the user agent string to make it look like this is a real browsercurl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //if a simple http redirect is recieved, setting this to 1 will cause curl to follow the urlcurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //this causes the data retrieved to be returned by the curl_exec function below instead of being printedcurl_setopt($ch, CURLOPT_URL, $url_login); //sets the url to requestcurl_setopt($ch, CURLOPT_POST, 1); //this is a post request and not a get request like normalcurl_setopt($ch, CURLOPT_POSTFIELDS, $postData); //the post data to be sent with the request$data = curl_exec ($ch); //execute the requestcurl_close ($ch); //close the curl sessionunset($ch); //destroy the curl session.$ch = curl_init();curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieJar);curl_setopt($ch, CURLOPT_URL, $url_view);$result = curl_exec ($ch);curl_close ($ch);echo $result;?>[/code]My problem is when i execute this script it logs me in but shows the http://tracks.tra.in/ home page on my domain (www.mysite.com/tracks.php shows http://tracks.tra.in/). Once the script has logged me in i need to be redirected to that site but still stay logged in.Please help . . .Thanks,Charlie Quote Link to comment https://forums.phpfreaks.com/topic/18092-php-login-to-site-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.