Новичок
Профиль
Группа: Участник
Сообщений: 5
Регистрация: 11.10.2007
Репутация: нет Всего: нет
|
Столкнулся со странным поведением curl . Пишу скрипт для логина в админку через курл. Когда запускаю скрипт через браузер, все ок, на выдаче страница из админки, но когда зпускаю с консоли - получаю страницу авторизации. В чем может быть проблема, не сталкивался ли кто с такой ошибкой? | Код | <?php ini_set("memory_limit","1000M"); require_once "app/Mage.php"; umask(0); Mage::app(); exec("php -f /home/slava/www/demofashion.loc/shell/mag_login.php", $result); $loginInformation = json_decode($result[0]); $sessionId = $loginInformation->sessionId; $formKey = $loginInformation->formKey; $postdata[] = "form_key=$formKey"; $postdata[] = "login[username]=admin"; $postdata[] = "login[password]=admin123"; $postdatastring = implode('&', $postdata); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://demofashion.loc/index.php/admin/cms_page/");
curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.1) Gecko/20100101 Firefox/10.0.1"); curl_setopt($ch, CURLOPT_TIMEOUT, 100 ); curl_setopt($ch, CURLOPT_COOKIE, "adminhtml=$sessionId" ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt(curl, CURLOPT_HTTPPOST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdatastring); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, true); $buffer = curl_exec($ch); echo "curl_errno: "; var_dump( curl_errno( $ch ) ); echo "curl_error: "; var_dump( curl_error( $ch ) ); echo "curl_getinfo: "; mage::d(curl_getinfo($ch)); var_dump($buffer);
|
на выходе в консоле получаем следующее | Код | * About to connect() to demofashion.loc port 80 (#0) * Trying 127.0.0.1... * connected * Connected to demofashion.loc (127.0.0.1) port 80 (#0) > POST /index.php/admin/cms_page/ HTTP/1.1 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 Host: demofashion.loc Accept: */* Cookie: adminhtml=95nva491j5svppfnpn7q2fe2o1 Content-Length: 72 Content-Type: application/x-www-form-urlencoded
< HTTP/1.1 302 Found < Date: Fri, 03 Aug 2012 14:58:39 GMT < Server: Apache/2.4.2 (Unix) OpenSSL/1.0.1c PHP/5.4.4 < X-Powered-By: PHP/5.4.4 < Expires: Thu, 19 Nov 1981 08:52:00 GMT < Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 < Pragma: no-cache < Set-Cookie: adminhtml=95nva491j5svppfnpn7q2fe2o1; expires=Tue, 07-Aug-2012 18:58:40 GMT; path=/; domain=demofashion.loc < Set-Cookie: adminhtml=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=demofashion.loc < Set-Cookie: adminhtml=lhaactj6li0ml3e4l5tnjmv0j5; expires=Tue, 07-Aug-2012 18:58:40 GMT; path=/ < Location: /index.php/admin/cms_page/ < Content-Length: 0 < Content-Type: text/html < * Connection #0 to host demofashion.loc left intact * Issue another request to this URL: 'http://demofashion.loc/index.php/admin/cms_page/' * Violate RFC 2616/10.3.3 and switch from POST to GET * Re-using existing connection! (#0) with host demofashion.loc * Connected to demofashion.loc (127.0.0.1) port 80 (#0) > GET /index.php/admin/cms_page/ HTTP/1.1 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 Host: demofashion.loc Accept: */* Referer: http://demofashion.loc/index.php/admin/cms_page/ Cookie: adminhtml=95nva491j5svppfnpn7q2fe2o1
< HTTP/1.1 200 OK < Date: Fri, 03 Aug 2012 14:58:40 GMT < Server: Apache/2.4.2 (Unix) OpenSSL/1.0.1c PHP/5.4.4 < X-Powered-By: PHP/5.4.4 < Expires: Thu, 19 Nov 1981 08:52:00 GMT < Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 < Pragma: no-cache < Set-Cookie: adminhtml=95nva491j5svppfnpn7q2fe2o1; expires=Tue, 07-Aug-2012 18:58:40 GMT; path=/; domain=demofashion.loc < Content-Length: 3382 < Content-Type: text/html; charset=UTF-8 < * Connection #0 to host demofashion.loc left intact curl_errno: int(0) curl_error: string(0) "" curl_getinfo:
array(23) { ["url"] => string(48) "http://demofashion.loc/index.php/admin/cms_page/" ["content_type"] => string(24) "text/html; charset=UTF-8" ["http_code"] => int(200) ["header_size"] => int(1132) ["request_size"] => int(635) ["filetime"] => int(-1) ["ssl_verify_result"] => int(0) ["redirect_count"] => int(1) ["total_time"] => float(2.634121) ["namelookup_time"] => float(3.1E-5) ["connect_time"] => float(3.5E-5) ["pretransfer_time"] => float(4.4E-5) ["size_upload"] => float(72) ["size_download"] => float(3382) ["speed_download"] => float(1283) ["speed_upload"] => float(27) ["download_content_length"] => float(3382) ["upload_content_length"] => float(0) ["starttransfer_time"] => float(2.052668) ["redirect_time"] => float(0.581313) ["certinfo"] => array(0) { } ["primary_ip"] => string(9) "127.0.0.1" ["redirect_url"] => string(0) "" }
string(4514) "HTTP/1.1 302 Found Date: Fri, 03 Aug 2012 14:58:39 GMT Server: Apache/2.4.2 (Unix) OpenSSL/1.0.1c PHP/5.4.4 X-Powered-By: PHP/5.4.4 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: adminhtml=95nva491j5svppfnpn7q2fe2o1; expires=Tue, 07-Aug-2012 18:58:40 GMT; path=/; domain=demofashion.loc Set-Cookie: adminhtml=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=demofashion.loc Set-Cookie: adminhtml=lhaactj6li0ml3e4l5tnjmv0j5; expires=Tue, 07-Aug-2012 18:58:40 GMT; path=/ Location: /index.php/admin/cms_page/ Content-Length: 0 Content-Type: text/html
HTTP/1.1 200 OK Date: Fri, 03 Aug 2012 14:58:40 GMT Server: Apache/2.4.2 (Unix) OpenSSL/1.0.1c PHP/5.4.4 X-Powered-By: PHP/5.4.4 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: adminhtml=95nva491j5svppfnpn7q2fe2o1; expires=Tue, 07-Aug-2012 18:58:40 GMT; path=/; domain=demofashion.loc Content-Length: 3382 Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en"> <head> </head> <body id="page-login" onload="document.forms.loginForm.username.focus();"> ++++++++++++++++ Страница авторизации +++++++++++++++++++++ </body> </html>
" * Closing connection #0
|
Запускаю этот скрипт через браузер, получаю следующее: | Код | curl_errno: int(0) curl_error: string(0) "" curl_getinfo:
array(23) { ["url"] => string(48) "http://demofashion.loc/index.php/admin/cms_page/" ["content_type"] => string(24) "text/html; charset=UTF-8" ["http_code"] => int(200) ["header_size"] => int(461) ["request_size"] => int(359) ["filetime"] => int(-1) ["ssl_verify_result"] => int(0) ["redirect_count"] => int(0) ["total_time"] => float(2.415623) ["namelookup_time"] => float(0.000159) ["connect_time"] => float(0.000237) ["pretransfer_time"] => float(0.000243) ["size_upload"] => float(72) ["size_download"] => float(62760) ["speed_download"] => float(25980) ["speed_upload"] => float(29) ["download_content_length"] => float(-1) ["upload_content_length"] => float(0) ["starttransfer_time"] => float(2.391751) ["redirect_time"] => float(0) ["certinfo"] => array(0) { } ["primary_ip"] => string(9) "127.0.0.1" ["redirect_url"] => string(0) "" } string(63221) "HTTP/1.1 200 OK Date: Fri, 03 Aug 2012 15:02:39 GMT Server: Apache/2.4.2 (Unix) OpenSSL/1.0.1c PHP/5.4.4 X-Powered-By: PHP/5.4.4 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: adminhtml=19ne6s0sul1km8cum30ppptg17; expires=Tue, 07-Aug-2012 19:02:39 GMT; path=/; domain=demofashion.loc Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head> <body id="page-login" onload="document.forms.loginForm.username.focus();"> ++++++++++++++++ Страница из админки!! +++++++++++++++++++++ </body> </html>
|
В чем может быть причина, подскажите, у кого есть какие предположение.
|