derrickc Posted April 28, 2010 Share Posted April 28, 2010 Im trying to login to a page and scrape the welcome page. i know this is supposed to be easy but i havent been able to figure it out. The page is t-mobile.com you have to enter your phone number and password. It isnt working. I have tried many different versions. If you can help point me in the right direction that would be great. here is the code i have. thanks! <? $phoneNumber = '8010000000'; $message = 'mypassword'; $curlPost = 'Login1:txtMSISDN=' . urlencode($phoneNumber) . '&Login1:txtPassword=' . urlencode($message); $fp = fopen("cookie.txt", "w"); fclose($fp); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($ch, CURLOPT_URL, 'https://my.t-mobile.com/Login/?rc=&dest=https%3a%2f%2fmy.t-mobile.com%3a443%2fDefault.aspx'); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $data = curl_exec($ch); curl_close($ch); echo $data; ?> Link to comment https://forums.phpfreaks.com/topic/200008-login-to-a-site-with-curl/ Share on other sites More sharing options...
cags Posted April 28, 2010 Share Posted April 28, 2010 I'm not sure why you think it's supposed to be easy, but what you're attempting most likely will not be. If the site you were attempting to login to was made with php then yes it might not be too bad, but aspx sites are a different matter entirely. You will need to scrape the entire contents of the login page. From that you will need to extract various bits of information, on the page you are looking at possibly only __VIEWSTATE, but there is normally 2 fields you require. You also need to make sure you store the cookies. Once you have done this you can then make a second call to curl_exec(), this time including both the two login values that you already have and also the __VIEWSTATE value. Link to comment https://forums.phpfreaks.com/topic/200008-login-to-a-site-with-curl/#findComment-1049772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.