[Programming] Hỏi nguyên nhân cURL không thành công khi login |
03/09/2011 16:35:56 (+0700) | #1 | 246445 |
MINH99
Member
|
0 |
|
|
Joined: 12/02/2010 01:38:27
Messages: 9
Offline
|
|
Chào mọi người .Mình viết một code login vào https://myoffice.bt.com/ bằng Php Curl.Mặc dù đã dùng đủ các tham số.Giả lập các header gửi đi .Mới học Curl nên thử trang này.Sao mà xui thế smilie .Mong mọi ngừoi giúp đỡ smilie
Đây là code của tôi :
Code:
https://myoffice.bt.com/siteminderagent/forms/login.fcc
POST /siteminderagent/forms/login.fcc HTTP/1.1
Host: myoffice.bt.com
User-Agent: Mozilla/4.0 (Windows NT 4.1; rv:0.0.1) Gecko/57675645 Firefox/4.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: https://myoffice.bt.com/login.aspx?TYPE=33554432&REALMOID=06-5f65a644-8f92-102f-9e92-83aaa3f30cb3&GUID=0&SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=$SM$KZj%2fCu0bd3NnyMauD%2fB9M%2bIq7ILEq9IA%2fx4SpXxOqj9waedh4eGmMUDQQXSEhjeV&TARGET=$SM$https%3a%2f%2fmyoffice%2ebt%2ecom%2fsm%2fprivatecreatesession%2easpx%3fsiteArea%3dbtb%2emya%26TARGET%3dhttps$%3a$%2f$%2femail2%2ebtconnect%2ebt%2ecom$%2fexchange$%2f
Cookie: .DBANON=7-N-g_mBwj6m9NCBJQgFjq-M7dOzwgUJStD0oX042y_0TG-No4anKHQdCEt9ONnAmWsEVP5YzmcT3hgshy0F1gD7wQOukXr6SeGPKuh3QHI1; ASP.NET_SessionId=ex1wg245lj4ygt45rm0gcy45; s_cc=true; s_sq=%5B%5BB%5D%5D; testCookieBT=true; testCookieInLogin=true; MyOId=; HTTP_SAAS_INCIDENT_LEVEL=2; SMSESSION=LOGGEDOFF; SessionType=Public; JSESSIONID_btv=jTrPThLpHqGyW7qmBN72y1kMd3rWzrSnvrLq4gqy41PysJpFzxvv!-732958611; btcomsite=r; UserId=
Content-Type: application/x-www-form-urlencoded
Content-Length: 2538
__VIEWSTATE=HrRlHLGhrOTaomsgPZbItjoMYDju0jTFQ2L51ykIiZ%2BdEarNbj%2Bz3rgPgtIwrqCwt16kuaF8SoJpOuqQE0ri5sny6rFlIGT33wn9Rg4Qso%2Fm8YeSaMv0pyQWuzzbAy2bE1el1EcFFmR6sUIM0IHevdBRlHQoO1fZuZEPMl0TwyFE6dzdcO%2BOj94%2FywgSMrqI9lVgODJFjATOXmzF5R%2FDhRt%2FsOSOqs7jywRsgguRdMOfkoH2kfnE%2FJzd2AcbKmSSXkXW3iPOb%2BUObFs0m6nI2gf5nX%2F6aaAEf6nWNTN7FoaK5HsQ%2BWpOz16YP%2FkujxVyuCojxJM2F6bI4k7HTJc5l439oMkaPzgYmR0KJxRtDqa4nHRp1qaWuEPjN%2BAuJh%2FCrWPiWQN72spXNsUXEVRx12EiSK0QezQhe3aozb7JSNUOYY4FNsFpGJGKfo7cVIrCMdfgzZVQlA%2B2JumgTAJLRVlYZ5CUo8Y6TfmVlLRK0crU%2FCWKy0DeNSBypU5gbb6iHFeq5I%2Bf0aro0GCF9fIxezfpCxTEj4jctXlzIYWLqh2AlqlLqFpbPbTX3QhXcDvmb4JKWMnw%2Bm0K9pRLlXo%2FoopWQencslmvAXP4x0CDtTy9T2QYS7X6KAQ6CIOYutKCPb%2FGjgcanSEe0zpMn8nfwEjCf474TNCih5uXiy5aH0VEMSuTw%2Ff1GNJ0Fc333nq33Lce8iNTYsVcfZQaTMO1wfQAAyFNWidJ%2B4FdAXwUiKbod28rI1hKcJePRKao12wP%2Fr6m3D0OZKlwflXtJxVwocKOuWaRt8itjxYZuVrlb9FfG8VWzg6cc3jG77wWwoq0FhK4mNllRGS3RStlcnQ4t6i0Pcs2bwQBkR1rGjnmWD66fdk1jdLldmvzTsWsFt9M4ALd8HgAcSp1O3jAtrSukTi2Js7A%2BKT6u0kcwWLBL4LiL3lYDhjxgoD7Qqrv54ZjyuTPK6RXLNh5%2BFkYKDb%2BiC7RXnLgrQg4jA14e4E19i8Uq2FJc9kpmuWTFParY4f2znYzSH2IJVaPOHFyHCd%2BL9ycQPcOKhRXQARZhjo%2FZpp%2BIkX2suXmGlVZDz9jYcPx8QRAExceia6mneEJ3Ccal0fpeOjgYRfeJkYbEMfo3paiCDpZdYQUdto%2Br73D%2BWu1XwysKCvsN03DiPstpyicWjbN%2BCjIZRscFbipBZPc%2FIVR9XDZ1QijP2Biwo6h3utZD5vFG124hDfAFHa1cOrm5%2FpPj6NnIS%2F%2Bv%2F9QJO7z%2B3pEA7dy1Wtt0OIXFp%2F6RX%2B8MQYtxTPOTA9BRr7ARdmCmukuKvVQfPyTNV2wkQxYdj8itgAkNStgLw%3D%3D&Segment=btb.hub&SubSegment=&searchType=0&searchPlatform=BEA&lob=btb.hub&queryText=&searchText=&USER=".urlencode($maill)."&PASSWORD=".$passs."&SMENC=ISO-8859-1&SMLOCALE=US-EN&userFirstLoginUrl=https%3A%2F%2Fmyoffice.bt.com%2FManageBusinessApplications%2FSecretQA.aspx&PrivateLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fprivatecreatesession.aspx%3FsiteArea%3Dbtb.mya&PublicLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya&target=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya%26TARGET%3Dhttps%253a%252f%252femail2.btconnect.bt.com%252fexchange%252f&submitStatus=&smauthreason=&smagentname=&postpreservationdata=&AnonUserName=anon%40myoffice.bt.com&authMode=SITEMINDER&smUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsiteminderagent%2Fforms%2Flogin.fcc¬SMUrl=https%3A%2F%2Fmyoffice.bt.com%2Fdefault.aspx&smIdentifier=1";
HTTP/1.1 302 Object Moved
Cache-Control: no-store
P3P: CP=""
Location: https://myoffice.bt.com/sm/createsession.aspx?siteArea=btb.mya&TARGET=https%3a%2f%2femail2.btconnect.bt.com%2fexchange%2f
Content-Length: 0
Set-Cookie: SMTRYNO=; expires=Man, 09 O 2011 016:37:58 GMT; path=/; domain=.bt.com
Set-Cookie: HTTP_SAAS_INCIDENT_LEVEL=0; path=/; domain=.bt.com
Set-Cookie: SMSESSION=zh4Zqaoua5m6GHL1woyi0PVaj/HEAvrGwZ8Ir6R2/SZJ0UVRxBBngJvMsEBddv5kjJOL8yNmbKxcWx2zVMFVrCNVi0PfCHinxS67EZl+uV4vPBRKDSLu4oObSNzGG8PRoSNT/j/dU2DRC5Ab62+42Wz74WFS5YYH5EbFiXGcBYh7c7iGYbJURlu+4bAbhu4p3U71fHC34iT02oyLMpxkWP8//qXK3ziNNaJ52LvQQ7aQneqCNvIaQiRxQYjEcY9fMCvic4bONTychCf6/qwkfhyNbFw4bhe5iikt+MWgJRdqPQgMV7g10TQDLwnKtfULWK4cjJ/McUS1k903fjsNuYNeEGa2/F4iM6wsZozkicGAhHfb42fyWcYtHDERmHszDmCBT4Ua7Zt0Z9MJUOYv+Wow3Ux7p+ce0cltbJW8+QREJrJL7IvXUrWhixhJoHitB+S3dUVFyaTl7eyvOnkDTLZZcZzynuIdpk9oFYHIhcd+SrBPi8fO2ZTgEsOTYt9ilbUk82LCnmNty7bQxKwZnSHYyyIEcTrkWW5K85gjlcYQCqyHOYb94ejcKlGKy1esFen9Kz5z0A9zvor3cp82OUDciMyQ4HCFsiAtXIvMpI6E6mXiYM++r1+RBN9YagHUGKqyHZ9yC0OeZ0gJ2IeH+H9MF9WFkgGEVmcaKmYiQBphoZhzLjQxbMd/D1dy8PxPHEjqVQSGtl7q11/mSs7ZrlSsMCOGNByuR6a6H8EfdzE4Gz82H41Gpmmn/8xB6VlQaRG+TwEfS23HvCTYaItL8OGr7MuV3/JaPWJXP72fWWlgPahlieWqMLsTc/QojtDv1GZk7jMsRZceAWcpEq3dmcz0oipA3Fg/j+ctL5Wraozlyte6bcYm1UpDpq4ToVR1jlBdYB0dB/psHf0ZHmM943P5XIuqnuV8eqXHd9UKnS/n+eNBdPlKnaKyoryglNN1R3YExLRpy23jdSpkS3/GQIHH7jN9YWGt/DI+Oen8J+zQI9UDv2Fuon7snBkxxZucPXWhwpJkmViQYLrLO/zQqwX/fOJkztm+ooQcacr+aa7Smu6kmier9g7gF5e3iA7m; path=/; domain=.bt.com
Code :
Code:
function btconnect($maill,$passs){
$url = "https://myoffice.bt.com/siteminderagent/forms/login.fcc";
$header[0] = "POST /siteminderagent/forms/login.fcc HTTP/1.1";
$header[1] = "Host: myoffice.bt.com";
$header[2] = "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1";
$header[3] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$header[4] = "Accept-Language: en-us,en;q=0.5";
$header[5] = "Accept-Encoding: gzip, deflate";
$header[6] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[7] = "Connection: keep-alive";
$header[8] = "Content-Type: application/x-www-form-urlencoded";
/
$postvars ="__VIEWSTATE=HrRlHLGhrOTaomsgPZbItjoMYDju0jTFQ2L51ykIiZ%2BdEarNbj%2Bz3rgPgtIwrqCwt16kuaF8SoJpOuqQE0ri5sny6rFlIGT33wn9Rg4Qso%2Fm8YeSaMv0pyQWuzzbAy2bE1el1EcFFmR6sUIM0IHevdBRlHQoO1fZuZEPMl0TwyFE6dzdcO%2BOj94%2FywgSMrqI9lVgODJFjATOXmzF5R%2FDhRt%2FsOSOqs7jywRsgguRdMOfkoH2kfnE%2FJzd2AcbKmSSXkXW3iPOb%2BUObFs0m6nI2gf5nX%2F6aaAEf6nWNTN7FoaK5HsQ%2BWpOz16YP%2FkujxVyuCojxJM2F6bI4k7HTJc5l439o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Type=0&searchPlatform=BEA&lob=btb.hub&queryText=&searchText=&USER=[color=red]".urlencode($maill)."&PASSWORD=".$passs."&[/color]SMENC=ISO-8859-1&SMLOCALE=US-EN&userFirstLoginUrl=https%3A%2F%2Fmyoffice.bt.com%2FManageBusinessApplications%2FSecretQA.aspx&PrivateLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fprivatecreatesession.aspx%3FsiteArea%3Dbtb.mya&PublicLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya&target=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya%26TARGET%3Dhttps%253a%252f%252femail2.btconnect.bt.com%252fexchange%252f&submitStatus=&smauthreason=&smagentname=&postpreservationdata=&AnonUserName=anon%40myoffice.bt.com&authMode=SITEMINDER&smUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsiteminderagent%2Fforms%2Flogin.fcc¬SMUrl=https%3A%2F%2Fmyoffice.bt.com%2Fdefault.aspx&smIdentifier=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec ($ch);
curl_close ($ch);}
Nhưng mình thử dùng addon LIVE HTTP HEADERS firefox
Phần HTTP headers:
Mình xoá hết chừa
Code:
Host: myoffice.bt.com
Content-Type: application/x-www-form-urlencoded[/quote]
phần sent POST content. Phần này mình chỉ cần thay đổi mail và pass là có thể đăng nhập được.
nhưng khi code chỉ 2 cái
$header[0] = "Host: myoffice.bt.com";
$header[1] = "Content-Type: application/x-www-form-urlencoded";
và giống code trên thì nó không đăng nhập được. Và mình cũng thử cho tất cả header của nó vào cũng không được
Phần sent POST content
[quote]
__VIEWSTATE=HrRlHLGhrOTaomsgPZbItjoMYDju0jTFQ2L51ykIiZ%2BdEarNbj%2Bz3rgPgtIwrqCwt16kuaF8SoJpOuqQE0ri5sny6rFlIGT33wn9Rg4Qso%2Fm8YeSaMv0pyQWuzzbAy2bE1el1EcFFmR6sUIM0IHevdBRlHQoO1fZuZEPMl0TwyFE6dzdcO%2BOj94%2FywgSMrqI9lVgODJFjATOXmzF5R%2FDhRt%2FsOSOqs7jywRsgguRdMOfkoH2kfnE%2FJzd2AcbKmSSXkXW3iPOb%2BUObFs0m6nI2gf5nX%2F6aaAEf6nWNTN7FoaK5HsQ%2BWpOz16YP%2FkujxVyuCojxJM2F6bI4k7HTJc5l439oMkaPzgYmR0KJxRtDqa4nHRp1qaWuEPjN%2BAuJh%2FCrWPiWQN72spXNsUXEVRx12EiSK0QezQhe3aozb7JSNUOYY4FNsFpGJGKfo7cVIrCMdfgzZVQlA%2B2JumgTAJLRVlYZ5CUo8Y6TfmVlLRK0crU%2FCWKy0DeNSBypU5gbb6iHFeq5I%2Bf0aro0GCF9fIxezfpCxTEj4jctXlzIYWLqh2AlqlLqFpbPbTX3QhXcDvmb4JKWMnw%2Bm0K9pRLlXo%2FoopWQencslmvAXP4x0CDtTy9T2QYS7X6KAQ6CIOYutKCPb%2FGjgcanSEe0zpMn8nfwEjCf474TNCih5uXiy5aH0VEMSuTw%2Ff1GNJ0Fc333nq33Lce8iNTYsVcfZQaTMO1wfQAAyFNWidJ%2B4FdAXwUiKbod28rI1hKcJePRKao12wP%2Fr6m3D0OZKlwflXtJxVwocKOuWaRt8itjxYZuVrlb9FfG8VWzg6cc3jG77wWwoq0FhK4mNllRGS3RStlcnQ4t6i0Pcs2bwQBkR1rGjnmWD66fdk1jdLldmvzTsWsFt9M4ALd8HgAcSp1O3jAtrSukTi2Js7A%2BKT6u0kcwWLBL4LiL3lYDhjxgoD7Qqrv54ZjyuTPK6RXLNh5%2BFkYKDb%2BiC7RXnLgrQg4jA14e4E19i8Uq2FJc9kpmuWTFParY4f2znYzSH2IJVaPOHFyHCd%2BL9ycQPcOKhRXQARZhjo%2FZpp%2BIkX2suXmGlVZDz9jYcPx8QRAExceia6mneEJ3Ccal0fpeOjgYRfeJkYbEMfo3paiCDpZdYQUdto%2Br73D%2BWu1XwysKCvsN03DiPstpyicWjbN%2BCjIZRscFbipBZPc%2FIVR9XDZ1QijP2Biwo6h3utZD5vFG124hDfAFHa1cOrm5%2FpPj6NnIS%2F%2Bv%2F9QJO7z%2B3pEA7dy1Wtt0OIXFp%2F6RX%2B8MQYtxTPOTA9BRr7ARdmCmukuKvVQfPyTNV2wkQxYdj8itgAkNStgLw%3D%3D&Segment=btb.hub&SubSegment=&searchType=0&searchPlatform=BEA&lob=btb.hub&queryText=&searchText=&USER=[color=red]".urlencode($maill)."&PASSWORD=".$passs."&[/color]SMENC=ISO-8859-1&SMLOCALE=US-EN&userFirstLoginUrl=https%3A%2F%2Fmyoffice.bt.com%2FManageBusinessApplications%2FSecretQA.aspx&PrivateLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fprivatecreatesession.aspx%3FsiteArea%3Dbtb.mya&PublicLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya&target=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya%26TARGET%3Dhttps%253a%252f%252femail2.btconnect.bt.com%252fexchange%252f&submitStatus=&smauthreason=&smagentname=&postpreservationdata=&AnonUserName=anon%40myoffice.bt.com&authMode=SITEMINDER&smUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsiteminderagent%2Fforms%2Flogin.fcc¬SMUrl=https%3A%2F%2Fmyoffice.bt.com%2Fdefault.aspx&smIdentifier=1
|
|
|
|
|
[Programming] Hỏi nguyên nhân cURL không thành công khi login |
03/09/2011 21:38:03 (+0700) | #2 | 246455 |
|
xnohat
Moderator
|
Joined: 30/01/2005 13:59:19
Messages: 1210
Location: /dev/null
Offline
|
|
Thêm dòng này vào mã PHP và gửi báo lỗi của cURL lên đây
Code:
echo 'Curl error: ' . curl_error($ch);
P/s: lần sau bồ nên đưa các phần "code" vào trong tag [ code ] [ /code ] chứ đừng để trong tag [ quote ] , nó làm forum bị bể frame rất khó coi |
|
iJust clear, "What I need to do and how to do it"/i
br
brBox tán gẫu dời về: http://www.facebook.com/hvaonline |
|
|
|
[Programming] Hỏi nguyên nhân cURL không thành công khi login |
04/09/2011 10:38:49 (+0700) | #3 | 246463 |
MINH99
Member
|
0 |
|
|
Joined: 12/02/2010 01:38:27
Messages: 9
Offline
|
|
Mình thay $maill = " "; $passs = " "; echo 'Curl error: ' . curl_error($ch); vào rồi mà không hiểu sao nó hiện ra trang trắng.
Code:
<?php
$url = "https://myoffice.bt.com/siteminderagent/forms/login.fcc";
$header[0] = "POST /siteminderagent/forms/login.fcc HTTP/1.1";
$header[1] = "Host: myoffice.bt.com";
$header[2] = "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1";
$header[3] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$header[4] = "Accept-Language: en-us,en;q=0.5";
$header[5] = "Accept-Encoding: gzip, deflate";
$header[6] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[7] = "Connection: keep-alive";
$header[8] = "Content-Type: application/x-www-form-urlencoded";
$maill = " ";
$passs = " ";
$postvars ="__VIEWSTATE=HrRlHLGhrOTaomsgPZbItjoMYDju0jTFQ2L51ykIiZ%2BdEarNbj%2Bz3rgPgtIwrqCwt16kuaF8SoJpOuqQE0ri5sny6rFlIGT33wn9Rg4Qso%2Fm8YeSaMv0pyQWuzzbAy2bE1el1EcFFmR6sU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N03DiPstpyicWjbN%2BCjIZRscFbipBZPc%2FIVR9XDZ1QijP2Biwo6h3utZD5vFG124hDfAFHa1cOrm5%2FpPj6NnIS%2F%2Bv%2F9QJO7z%2B3pEA7dy1Wtt0OIXFp%2F6RX%2B8MQYtxTPOTA9BRr7ARdmCmukuKvVQfPyTNV2wkQxYdj8itgAkNStgLw%3D%3D&Segment=btb.hub&SubSegment=&searchType=0&searchPlatform=BEA&lob=btb.hub&queryText=&searchText=&USER=".urlencode($maill)."&PASSWORD=".$passs."&SMENC=ISO-8859-1&SMLOCALE=US-EN&userFirstLoginUrl=https%3A%2F%2Fmyoffice.bt.com%2FManageBusinessApplications%2FSecretQA.aspx&PrivateLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fprivatecreatesession.aspx%3FsiteArea%3Dbtb.mya&PublicLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya&target=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya%26TARGET%3Dhttps%253a%252f%252femail2.btconnect.bt.com%252fexchange%252f&submitStatus=&smauthreason=&smagentname=&postpreservationdata=&AnonUserName=anon%40myoffice.bt.com&authMode=SITEMINDER&smUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsiteminderagent%2Fforms%2Flogin.fcc¬SMUrl=https%3A%2F%2Fmyoffice.bt.com%2Fdefault.aspx&smIdentifier=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec ($ch);
echo 'Curl error: ' . curl_error($ch);
?>
Nhưng mình dùng Addon firefox Live HTTP headers
và nhấn Replay thì nó lạy đăng nhập thành công.
Code trên code không biết nó còn thiếu gì nữa bạn mà cho đăng nhập thành công
|
|
|
|
|
[Programming] Hỏi nguyên nhân cURL không thành công khi login |
04/09/2011 10:57:28 (+0700) | #4 | 246464 |
|
angel-pc
Member
|
0 |
|
|
Joined: 01/01/2011 01:15:32
Messages: 63
Offline
|
|
theo mình bạn nên giả lập việc load trang đó một cách có trình tự để lấy
đúng giá trị của các tham số, chứ không thể chơi ngang xương như vậy được
Code:
$postvars ="__VIEWSTATE=HrRlHLGhrOTaomsgPZbItjoMYDju0jTFQ2L51ykIiZ%2BdEarNbj%2Bz3rgPgtIwrqCwt16kuaF8SoJpOuqQE0ri5sny6rFlIGT33wn9Rg4Qso%2Fm8YeSaMv0pyQWuzzbAy2bE1el1EcFFmR6sUIM0IHevdBRlHQoO1fZuZEPMl0TwyFE6dzdcO%2BOj94%2FywgSMrqI9lVgODJFjATOXmzF5R%2FDhRt%2FsOSOqs7jywRsgguRdMOfkoH2kfnE%2FJzd2AcbKmSSXkXW3iPOb%2BUObFs0m6nI2gf5nX%2F6aaAEf6nWNTN7FoaK5HsQ%2BWpOz16YP%2FkujxVyuCojxJM2F6bI4k7HTJc5l439oMkaPzgYmR0KJxRtDqa4nHRp1qaWuEPjN%2BAuJh%2FCrWPiWQN72spXNsUXEVRx12EiSK0QezQhe3aozb7JSNUOYY4FNsFpGJGKfo7cVIrCMdfgzZVQlA%2B2JumgTAJLRVlYZ5CUo8Y6TfmVlLRK0crU%2FCWKy0DeNSBypU5gbb6iHFeq5I%2Bf0aro0GCF9fIxezfpCxTEj4jctXlzIYWLqh2AlqlLqFpbPbTX3QhXcDvmb4JKWMnw%2Bm0K9pRLlXo%2FoopWQencslmvAXP4x0CDtTy9T2QYS7X6KAQ6CIOYutKCPb%2FGjgcanSEe0zpMn8nfwEjCf474TNCih5uXiy5aH0VEMSuTw%2Ff1GNJ0Fc333nq33Lce8iNTYsVcfZQaTMO1wfQAAyFNWidJ%2B4FdAXwUiKbod28rI1hKcJePRKao12wP%2Fr6m3D0OZKlwflXtJxVwocKOuWaRt8itjxYZuVrlb9FfG8VWzg6cc3jG77wWwoq0FhK4mNllRGS3RStlcnQ4t6i0Pcs2bwQBkR1rGjnmWD66fdk1jdLldmvzTsWsFt9M4ALd8HgAcSp1O3jAtrSukTi2Js7A%2BKT6u0kcwWLBL4LiL3lYDhjxgoD7Qqrv54ZjyuTPK6RXLNh5%2BFkYKDb%2BiC7RXnLgrQg4jA14e4E19i8Uq2FJc9kpmuWTFParY4f2znYzSH2IJVaPOHFyHCd%2BL9ycQPcOKhRXQARZhjo%2FZpp%2BIkX2suXmGlVZDz9jYcPx8QRAExceia6mneEJ3Ccal0fpeOjgYRfeJkYbEMfo3paiCDpZdYQUdto%2Br73D%2BWu1XwysKCvsN03DiPstpyicWjbN%2BCjIZRscFbipBZPc%2FIVR9XDZ1QijP2Biwo6h3utZD5vFG124hDfAFHa1cOrm5%2FpPj6NnIS%2F%2Bv%2F9QJO7z%2B3pEA7dy1Wtt0OIXFp%2F6RX%2B8MQYtxTPOTA9BRr7ARdmCmukuKvVQfPyTNV2wkQxYdj8itgAkNStgLw%3D%3D&Segment=btb.hub&SubSegment=&searchType=0&searchPlatform=BEA&lob=btb.hub&queryText=&searchText=&USER=[color=red]".urlencode($maill)."&PASSWORD=".$passs."&[/color]SMENC=ISO-8859-1&SMLOCALE=US-EN&userFirstLoginUrl=https%3A%2F%2Fmyoffice.bt.com%2FManageBusinessApplications%2FSecretQA.aspx&PrivateLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fprivatecreatesession.aspx%3FsiteArea%3Dbtb.mya&PublicLoginSuccessUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya&target=https%3A%2F%2Fmyoffice.bt.com%2Fsm%2Fcreatesession.aspx%3FsiteArea%3Dbtb.mya%26TARGET%3Dhttps%253a%252f%252femail2.btconnect.bt.com%252fexchange%252f&submitStatus=&smauthreason=&smagentname=&postpreservationdata=&AnonUserName=anon%40myoffice.bt.com&authMode=SITEMINDER&smUrl=https%3A%2F%2Fmyoffice.bt.com%2Fsiteminderagent%2Fforms%2Flogin.fcc¬SMUrl=https%3A%2F%2Fmyoffice.bt.com%2Fdefault.aspx&smIdentifier=1";
biến $header cũng không cần set quá nhiều vì khi khai báo bằng culrl_setopt thì cũng đồng nghĩa với việc thiết lập header, nên biến $header chỉ cần set những cái gì cần thiết thôi
nên set curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
và ghi kết quả trả về từ server để biết server thông báo gì
PS: nên bỏ cái này khỏi biến $header => "Accept-Encoding: gzip, deflate"; nếu muốn ghi ra file để xem kết quả
|
|
|
|
|
[Programming] Hỏi nguyên nhân cURL không thành công khi login |
04/09/2011 12:05:50 (+0700) | #5 | 246466 |
mv1098
Member
|
0 |
|
|
Joined: 18/07/2009 14:19:13
Messages: 119
Offline
|
|
Bạn thử với code này xem sao
phần $data bạn sửa cho phù hợp
nếu bạn có 1 account available ở site này thì share cho mình test giùm
( hình như bạn là dân UG phải hem )
Code:
<?php
function
curl_grab_page($url,$ref_url,$data,$login,$proxy,$proxystatus){
if($login == 'true') {
$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_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1");
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'true') {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $ref_url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
ob_start();
return curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
unset($ch);
}
$user = "";
$user = rawurlencode($user);
$pass = "";
$data = "&USER=".$user."&PASSWORD=".$pass; //vi du vay
echo curl_grab_page("https://myoffice.bt.com/siteminderagent/forms/login.fcc", "https://myoffice.bt.com/", $data, "true", "null", "false");
?>
|
|
|
|
|
[Programming] Hỏi nguyên nhân cURL không thành công khi login |
04/09/2011 12:43:59 (+0700) | #6 | 246468 |
MINH99
Member
|
0 |
|
|
Joined: 12/02/2010 01:38:27
Messages: 9
Offline
|
|
Mình nghĩ ở đây không dùng $ref_url cũng được. Nhưng code của cậu để nguyên đoạn data mình lấy được từ addon FF thì được chứ để $uer $pass nó không hiểu |
|
|
[Programming] Hỏi nguyên nhân cURL không thành công khi login |
04/09/2011 13:05:05 (+0700) | #7 | 246469 |
mv1098
Member
|
0 |
|
|
Joined: 18/07/2009 14:19:13
Messages: 119
Offline
|
|
câu hỏi ngoài lề mà bạn tập chung làm gì ?
bạn test thử cái code của mình xem đi đã |
|
|
[Programming] Hỏi nguyên nhân cURL không thành công khi login |
04/09/2011 13:40:39 (+0700) | #8 | 246471 |
MINH99
Member
|
0 |
|
|
Joined: 12/02/2010 01:38:27
Messages: 9
Offline
|
|
Thanks các cậu nhiều. Mình đã làm được rồi. Thanks nhiều. |
|
|
|