TechXpert Posted April 25, 2009 Share Posted April 25, 2009 My purpose is very simple. I will create a php page which will contain my login id and password and when i open that, it will submit that information to website concerned and that website willl log me in like a normal user. Please dont tell me its unsafe because i very well know its 90% unsafe. Till now I have compiled a code because i am a newbie in php (5 days) but from my view it only submits that form and does not log me in or moves me to that site or anything. So please modify the code. <?php //create array of data to be posted $post_data['emailAddress'] = 'emailAddress'; $post_data['password'] = 'password'; $post_data['submit'] = 'submit'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //create cURL connection $curl_connection = curl_init('https://login.yahoo.com/config/login'); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //perform our request $result = curl_exec($curl_connection); //show information regarding the request print_r(curl_getinfo($curl_connection)); echo curl_errno($curl_connection) . '-' . curl_error($curl_connection); //close the connection curl_close($curl_connection); ?> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 What's the purpose, might I ask? Yeah, I know you want to login, but what for? Quote Link to comment Share on other sites More sharing options...
TechXpert Posted April 25, 2009 Author Share Posted April 25, 2009 What's the purpose, might I ask? Yeah, I know you want to login, but what for? Well so that i dont have to write my password again and again. I am a kid of 15 years and my friend who becomes oversmart challenged me to do so. I beg u to solve my problem. Quote Link to comment Share on other sites More sharing options...
tefuzz Posted April 25, 2009 Share Posted April 25, 2009 What's the purpose, might I ask? Yeah, I know you want to login, but what for? Well so that i dont have to write my password again and again. I am a kid of 15 years and my friend who becomes oversmart challenged me to do so. I beg u to solve my problem. thats why browsers have "do you want me to remember this password?" and autoComplete... all you have to do is click twice, and your username and password are in. Quote Link to comment Share on other sites More sharing options...
TechXpert Posted April 25, 2009 Author Share Posted April 25, 2009 What's the purpose, might I ask? Yeah, I know you want to login, but what for? Well so that i dont have to write my password again and again. I am a kid of 15 years and my friend who becomes oversmart challenged me to do so. I beg u to solve my problem. thats why browsers have "do you want me to remember this password?" and autoComplete... all you have to do is click twice, and your username and password are in. Well i know that but my friend did it somehow. Can u please help me with the code. Please. I really want to shut the mouth of my friend. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 What's the purpose, might I ask? Yeah, I know you want to login, but what for? Well so that i dont have to write my password again and again. I am a kid of 15 years and my friend who becomes oversmart challenged me to do so. I beg u to solve my problem. What you're trying to do won't work. You can get it to log in, and you can get it to save your cookies and have it persist the login. However, when you fire up your browser you will still be logged out because your browser doesn't have the required cookie. Quote Link to comment Share on other sites More sharing options...
TechXpert Posted April 25, 2009 Author Share Posted April 25, 2009 What's the purpose, might I ask? Yeah, I know you want to login, but what for? Well so that i dont have to write my password again and again. I am a kid of 15 years and my friend who becomes oversmart challenged me to do so. I beg u to solve my problem. What you're trying to do won't work. You can get it to log in, and you can get it to save your cookies and have it persist the login. However, when you fire up your browser you will still be logged out because your browser doesn't have the required cookie. Sorry I am not able to explain you. I can take ages for me to explain why i want because I myself dont know correctly. But can you please correct my code so that i can log in and my cookies are kept. :-\ Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 Well, something like this: <?php //create array of data to be posted $post_data = array(); $post_data['emailAddress'] = 'emailAddress'; $post_data['password'] = 'password'; $post_data['submit'] = 'submit'; //create cURL connection $curl_connection = curl_init('https://login.yahoo.com/config/login'); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl_connection, CURLOPT_COOKIEJAR, 'cookies.txt'); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_data); //perform our request $result = curl_exec($curl_connection); //show information regarding the request print_r(curl_getinfo($curl_connection)); //close the connection curl_close($curl_connection); But what are you going to tell your friend? "I got a senior member on a PHP forum to do it, so I won the challenge". Anyway, let me make this clear to you. This will not log you in in your browser, but using the same cookie jar you will for any subsequent requests to the Yahoo server be logged in. So if you start Firefox, Internet Explorer, Google Chrome or whatever browser you use, you will still be logged out. You'll probably have to explain what you are trying to do. We aren't psychic. Edit: I might want to further add that I didn't actually check how Yahoo's login form looks. I assumed you did a proper job of gathering the required information. Quote Link to comment Share on other sites More sharing options...
TechXpert Posted April 25, 2009 Author Share Posted April 25, 2009 Well, something like this: <?php //create array of data to be posted $post_data = array(); $post_data['emailAddress'] = 'emailAddress'; $post_data['password'] = 'password'; $post_data['submit'] = 'submit'; //create cURL connection $curl_connection = curl_init('https://login.yahoo.com/config/login'); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl_connection, CURLOPT_COOKIEJAR, 'cookies.txt'); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_data); //perform our request $result = curl_exec($curl_connection); //show information regarding the request print_r(curl_getinfo($curl_connection)); //close the connection curl_close($curl_connection); But what are you going to tell your friend? "I got a senior member on a PHP forum to do it, so I won the challenge". Anyway, let me make this clear to you. This will not log you in in your browser, but using the same cookie jar you will for any subsequent requests to the Yahoo server be logged in. So if you start Firefox, Internet Explorer, Google Chrome or whatever browser you use, you will still be logged out. You'll probably have to explain what you are trying to do. We aren't psychic. Edit: I might want to further add that I didn't actually check how Yahoo's login form looks. I assumed you did a proper job of gathering the required information. Is there no way that I get redirected to the site and I am logined there ??? Or to insert the cookie itself in my browser ??? is there any alternate method to do this login via php ??? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 Okay, so I checked Yahoo's login form. This will log you in: <?php $loginInfo = array( 'login' => 'someone@yahoo.com', 'passwd' => 'abc123', ); $curlSettings = array( CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEJAR => 'cookies.txt', CURLOPT_FOLLOWLOCATION => true, CURLOPT_URL => 'https://login.yahoo.com/config/login', ); $ch = curl_init(); curl_setopt_array($ch, $curlSettings); $res = curl_exec($ch); preg_match_all('#<input type="hidden" name="([^"]+)" value="([^"]*)">#', $res, $matches); $formInfo = array('.save' => 'Sign In', '.persistent' => 'y'); for ($i = 0, $max = count($matches[2]); $i < $max; $i++) { $formInfo[$matches[1][$i]] = $matches[2][$i]; } $formInfo['.md5'] = $formInfo['.hash'] = $formInfo['.js'] = '1'; $loginInfo['passwd'] = md5(md5($loginInfo['passwd']) . $formInfo['.challenge']); $postData = array_merge($formInfo, $loginInfo); curl_setopt_array($ch, array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => array_merge($formInfo, $loginInfo), )); $res = curl_exec($ch); Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 Or to insert the cookie itself in my browser ??? Maybe, maybe not. I know Firefox uses an SQLite database to store its cookies. You could probably insert the cookies into that. I'm not going to do that for you unless you pay me though. Quote Link to comment Share on other sites More sharing options...
TechXpert Posted April 25, 2009 Author Share Posted April 25, 2009 Okay, so I checked Yahoo's login form. This will log you in: <?php $loginInfo = array( 'login' => 'someone@yahoo.com', 'passwd' => 'abc123', ); $curlSettings = array( CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEJAR => 'cookies.txt', CURLOPT_FOLLOWLOCATION => true, CURLOPT_URL => 'https://login.yahoo.com/config/login', ); $ch = curl_init(); curl_setopt_array($ch, $curlSettings); $res = curl_exec($ch); preg_match_all('#<input type="hidden" name="([^"]+)" value="([^"]*)">#', $res, $matches); $formInfo = array('.save' => 'Sign In', '.persistent' => 'y'); for ($i = 0, $max = count($matches[2]); $i < $max; $i++) { $formInfo[$matches[1][$i]] = $matches[2][$i]; } $formInfo['.md5'] = $formInfo['.hash'] = $formInfo['.js'] = '1'; $loginInfo['passwd'] = md5(md5($loginInfo['passwd']) . $formInfo['.challenge']); $postData = array_merge($formInfo, $loginInfo); curl_setopt_array($ch, array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => array_merge($formInfo, $loginInfo), )); $res = curl_exec($ch); I Tried this but nothing is happening. I am getting a white screen Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 Well, you still haven't told me what you want to happen except you want to login. The above script logs you in (assuming you put the correct credentials in the first array). Quote Link to comment Share on other sites More sharing options...
TechXpert Posted April 25, 2009 Author Share Posted April 25, 2009 Well, you still haven't told me what you want to happen except you want to login. The above script logs you in (assuming you put the correct credentials in the first array). I put the correct crdentials but i did not log in. I wanted to get redurected to yahoo home page with me logged in without any manual entry of cookies. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 What is it you don't understand? The browser has its own "cookie jar" and the script has its own "cookie jar". The script logs in and stores the cookies in its own cookie jar, and the browser still has its original cookies. If you now point your browser to Yahoo's home page it will not be logged in. I told you that you could investigate how Firefox stores its cookies in its SQLite database and then insert them manually into that. To do that you need to be a programmer or pay someone who already is a programmer to do it for you. I'm a programmer, so you can pay me to do it for you, or you can become a programmer and do it yourself. This is not a place where you go and say "make this script for me". Quote Link to comment 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.