Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [curl] Logowanie Gmail
user123
post
Post #1





Grupa: Zarejestrowani
Postów: 231
Pomógł: 2
Dołączył: 2.08.2006
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Witam,

czy wiecie może na czym polega błąd w poniższym kodzie logowanie do Gmail'a? Wszystko wydawaloby się w porządku ale po uruchomieniu pojawia sie strona gmail'a tylko z wpisanym loginem.

  1. <?php
  2. $cookie = 'cookie.txt';
  3. $loginUrl = 'https://www.google.com/accounts/';
  4. $login = '*****';
  5. $password = '******';
  6. $useragent = 'Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3';
  7.  
  8. $ch = curl_init( $loginUrl );
  9. curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookie );
  10. curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
  11. curl_setopt( $ch, CURLOPT_COOKIE, $cookie);
  12. curl_setopt( $ch, CURLOPT_USERAGENT, $useragent );
  13. curl_setopt( $ch, CURLOPT_REFERER, 'http://mail.google.com/mail/' );
  14. curl_setopt( $ch, CURLOPT_POST, 1 );
  15. curl_setopt( $ch, CURLOPT_POSTFIELDS, 'Email='.$login.'&Passwd='.$password );
  16. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  17. $page = curl_exec($ch);
  18. curl_close($ch);
  19. echo $page;
  20. ?>


proszę o pomoc

Ten post edytował user123 11.06.2009, 20:33:06
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 9)
Louner
post
Post #2





Grupa: Zarejestrowani
Postów: 99
Pomógł: 5
Dołączył: 20.06.2005
Skąd: Bielsk Podlaski

Ostrzeżenie: (0%)
-----


Gmail korzysta obficie z ajaxa; być może nie wszystko działa poprawnie, kiedy jest otwierane na innym serwerze.
Go to the top of the page
+Quote Post
erix
post
Post #3





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




A nie możesz korzystać z IMAP/POP3 do obsługi poczty...?
Go to the top of the page
+Quote Post
user123
post
Post #4





Grupa: Zarejestrowani
Postów: 231
Pomógł: 2
Dołączył: 2.08.2006
Skąd: Poznań

Ostrzeżenie: (10%)
X----


chciałem po prostu zalogować się na pocztę za pomoca Curl, a więc proszę o pomoc przy poprawie kodu i naprawdę dziekuję za alternatywy dla mojego sposobu rozwiązania:)
Go to the top of the page
+Quote Post
Savage.Mephisto
post
Post #5





Grupa: Zarejestrowani
Postów: 122
Pomógł: 11
Dołączył: 24.01.2008

Ostrzeżenie: (0%)
-----


Spróbuj w ten sposób:

  1. <?php
  2. $cookie = 'cookie.txt';
  3. $loginUrl = 'https://gmail.google.com/gmail/feed/atom';
  4. $login = '*****';
  5. $password = '******';
  6.  
  7. $ch = curl_init($loginUrl);
  8.  
  9. $headers = array(
  10.    "Host: gmail.google.com",
  11.    "Authorization: Basic ".base64_encode($login.':'.$password),
  12.    "User-Agent: Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3",
  13.    "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
  14.    "Accept-Language: pl;q=0.5",
  15.    "Accept-Encoding: text",
  16.    "Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7",
  17.    "Date: ".date(DATE_RFC822)
  18. );
  19.  
  20. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  21. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie );
  22. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie );
  23. curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  24. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  25. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  26. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  28. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  29. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  30. curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
  31.  
  32. $page = curl_exec($ch);
  33.  
  34. echo $page;
  35.  
  36. curl_close($ch);
  37. ?>
Go to the top of the page
+Quote Post
user123
post
Post #6





Grupa: Zarejestrowani
Postów: 231
Pomógł: 2
Dołączył: 2.08.2006
Skąd: Poznań

Ostrzeżenie: (10%)
X----


a dlaczego adres to ma być niby: https://gmail.google.com/gmail/feed/atom

po wywolaniu tego skryptu otrzymuje:

"Moved Permanently
The document has moved here."
Go to the top of the page
+Quote Post
Savage.Mephisto
post
Post #7





Grupa: Zarejestrowani
Postów: 122
Pomógł: 11
Dołączył: 24.01.2008

Ostrzeżenie: (0%)
-----


A po zmianie adresu na: https://www.google.com/accounts/ skrypt, który Ci podałem uruchamia się?
Go to the top of the page
+Quote Post
user123
post
Post #8





Grupa: Zarejestrowani
Postów: 231
Pomógł: 2
Dołączył: 2.08.2006
Skąd: Poznań

Ostrzeżenie: (10%)
X----


nadal otrzymuję:

"Moved Permanently
The document has moved here."

jakiś pomysł?(IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował user123 13.06.2009, 19:40:10
Go to the top of the page
+Quote Post
Savage.Mephisto
post
Post #9





Grupa: Zarejestrowani
Postów: 122
Pomógł: 11
Dołączył: 24.01.2008

Ostrzeżenie: (0%)
-----


U mnie ten skrypt z wywołaniem adresu: https://gmail.google.com/gmail/feed/atom śmiga bez żadnych problemów. Spróbuj jeszcze użyć adresu: https://gmail.google.com/gmail/feed/atom/ - czasem nie zamknięcie url'a znakiem / powoduje problemy.
BTW, pokaż kod znajdujący się w pliku cookie.txt.
Go to the top of the page
+Quote Post
user123
post
Post #10





Grupa: Zarejestrowani
Postów: 231
Pomógł: 2
Dołączył: 2.08.2006
Skąd: Poznań

Ostrzeżenie: (10%)
X----


@Savage.Mephisto niestety nic to nie dało;/ w pliku cookie.txt nie mam żadnej informacji, a po wywołaniu skryptu otrzymuję:

"Moved Permanently
The document has moved here."



to jak pomożecie? walczę z tym gmailem od paru dni i jakoś mi nie wychodzi;/

Ten post edytował user123 16.06.2009, 19:25:05
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.09.2025 - 10:42