webdevRefinery Forum: Login using cURL in HTTPS website - webdevRefinery Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rate Topic: -----

User is offline ta6ish 

  • Group: Members
  • Posts: 111
  • Joined: 09-March 10
  • Expertise:HTML,CSS,PHP,Javascript,SQL,Graphics,Flash

Posted 06 May 2012 - 02:22 PM (#1)

Login using cURL in HTTPS website


I've no experience of cURL. Please help, i need to login in the following website automatically.
https://accounts.sling.com
0


User is offline Qasim 

  • Group: Members
  • Posts: 520
  • Joined: 25-October 10
  • LocationOntario, Canada
  • Expertise:HTML,CSS,PHP,Java,Javascript,Graphics

Posted 06 May 2012 - 04:09 PM (#2)

What have you tried so far? What parameters have you passed? Make sure your cURL connection is even set to accept server certificates or else you will be getting errors :)
Qasim Iqbal
[HTML] [CSS] [JS] [PHP] [JAVA]
[ANDROID DEVELOPER] [CHROME WEB STORE DEVELOPER]
[WEBSITE] [FACEBOOK] [FORRST]
0


User is offline ta6ish 

  • Group: Members
  • Posts: 111
  • Joined: 09-March 10
  • Expertise:HTML,CSS,PHP,Javascript,SQL,Graphics,Flash

Posted 06 May 2012 - 09:58 PM (#3)

I've tried below noted code but this page redirecting back to login page.
$email = 'mail@inbox.com';
$pass = 'goeshere';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.sling.com/accounts/sling/start?next=http%3A%2F%2Faccounts.sling.com%2Faccounts%2Fmember%2Fprofile&flow=default&lang=ar&l=slingbox&policyCode=MAS&context=DEFAULT_SLINGBOX');
curl_setopt($ch, CURLOPT_POSTFIELDS,'emailAddress='.urlencode($email).'&password='.urlencode($pass).'&login=LOGIN');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
$page = curl_exec($ch);
echo $page;

0


User is offline Qasim 

  • Group: Members
  • Posts: 520
  • Joined: 25-October 10
  • LocationOntario, Canada
  • Expertise:HTML,CSS,PHP,Java,Javascript,Graphics

Posted 07 May 2012 - 07:05 AM (#4)

After a quick look at the website, it doesn't look like the page you are requesting in cURL is the page you should be requesting to login. Use an HTTP Listener/Packet sniffer or if your browser has a network debug panel, try that, and find out every event (or the first one) that happens after you click that log in button. Good luck
Qasim Iqbal
[HTML] [CSS] [JS] [PHP] [JAVA]
[ANDROID DEVELOPER] [CHROME WEB STORE DEVELOPER]
[WEBSITE] [FACEBOOK] [FORRST]
1


User is offline ta6ish 

  • Group: Members
  • Posts: 111
  • Joined: 09-March 10
  • Expertise:HTML,CSS,PHP,Javascript,SQL,Graphics,Flash

Posted 07 May 2012 - 08:53 AM (#5)

Thanks Qasim. Solved now :)
0


User is offline acronym 

  • Group: Members
  • Posts: 14
  • Joined: 28-May 12
  • LocationAustria
  • Expertise:HTML,CSS,PHP,Java,Javascript,SQL,Graphics

Posted 28 May 2012 - 08:34 AM (#6)

You asked so you shall be given :)

Working code:

<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', '1');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://accounts.sling.com/accounts/sling/login/loginForm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/test.cookie'); // replace this with /tmp or something like that
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(
    'emailAddress' => 'mail@email.com',
    'password' => 'your_password',
    'login' => 'LOGIN',
    'sessionFlow' => 'default',
    'sessionRedirectUrl' => 'http://accounts.sling.com/accounts/member/profile'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

echo $output; // you should see your profile page
?> 


Have fun!

Oh, sorry, missed the solve post... :(

This post has been edited by acronym: 28 May 2012 - 08:35 AM

Posted Image
1


User is offline ta6ish 

  • Group: Members
  • Posts: 111
  • Joined: 09-March 10
  • Expertise:HTML,CSS,PHP,Javascript,SQL,Graphics,Flash

Posted 03 June 2012 - 01:36 PM (#7)

One thing that i want to know is, how to load resources from the original website because it logs in correctly and not loading website resources from the http://accounts.sling.com but from local server. for example its loading css from localhost rather accounts.sling.com website.
/accounts/css/member__v31731.css

How to fix it?
0


User is offline Qasim 

  • Group: Members
  • Posts: 520
  • Joined: 25-October 10
  • LocationOntario, Canada
  • Expertise:HTML,CSS,PHP,Java,Javascript,Graphics

Posted 03 June 2012 - 01:49 PM (#8)

Are you outputting the HTML you are getting? In that case, you need to change all the paths to absolute paths to their server.
Qasim Iqbal
[HTML] [CSS] [JS] [PHP] [JAVA]
[ANDROID DEVELOPER] [CHROME WEB STORE DEVELOPER]
[WEBSITE] [FACEBOOK] [FORRST]
1


User is offline acronym 

  • Group: Members
  • Posts: 14
  • Joined: 28-May 12
  • LocationAustria
  • Expertise:HTML,CSS,PHP,Java,Javascript,SQL,Graphics

Posted 06 June 2012 - 02:13 PM (#9)

View Postta6ish, on 03 June 2012 - 01:36 PM, said:

One thing that i want to know is, how to load resources from the original website because it logs in correctly and not loading website resources from the http://accounts.sling.com but from local server. for example its loading css from localhost rather accounts.sling.com website.
/accounts/css/member__v31731.css

How to fix it?


This should do the trick if you want to print the content of the profile page.
<base href ="http://accounts.sling.com/" />


Otherwise you'll have to do a preg_replace on every <a> in the code you receive.
Posted Image
1


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services