{"id":400,"date":"2012-10-11T13:16:45","date_gmt":"2012-10-11T06:16:45","guid":{"rendered":"http:\/\/blog.trichev.com\/?p=400"},"modified":"2017-08-10T09:35:29","modified_gmt":"2017-08-10T02:35:29","slug":"php-authorization-with-curl","status":"publish","type":"post","link":"https:\/\/trichev.com\/blog\/2012\/10\/11\/php-authorization-with-curl\/","title":{"rendered":"PHP. Authorization with curl"},"content":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430: \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p>function get_info($email,$pass)<br \/>\n{<br \/>\n$ch = curl_init();<br \/>\n$url = &#8216;https:\/\/www.somesite.com\/login&#8217;;<br \/>\ncurl_setopt($ch, CURLOPT_URL, $url ); \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430<br \/>\ncurl_setopt($ch, CURLOPT_HEADER, 0); \/\/ \u043f\u0443\u0441\u0442\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438<br \/>\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0442\u043e \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u043b \u0441\u0435\u0440\u0432\u0435\u0440<br \/>\ncurl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); \/\/ \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0437\u0430 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0430\u043c\u0438<br \/>\ncurl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);\/\/ \u0442\u0430\u0439\u043c\u0430\u0443\u0442<br \/>\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\/\/ \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430<br \/>\ncurl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).&#8217;\/cookies.txt&#8217;); \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043a\u0443\u043a\u0438 \u0432 \u0444\u0430\u0439\u043b<br \/>\ncurl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).&#8217;\/cookies.txt&#8217;);<br \/>\ncurl_setopt($ch, CURLOPT_POST, 1); \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 post<br \/>\ncurl_setopt($ch, CURLOPT_POSTFIELDS, array(<br \/>\n&#8217;email&#8217;=&gt;$email,<br \/>\n&#8216;password&#8217;=&gt;$pass,<br \/>\n));<br \/>\n$data1 = curl_exec($ch);<\/p>\n<p># curl_setopt($ch, CURLOPT_URL, &#8216;http:\/\/www.somesite.com\/info\/index.php?ID=12345&#8217; );<br \/>\n# curl_setopt($ch, CURLOPT_POST, 0);<br \/>\n# $data2 = curl_exec($ch);<\/p>\n<p>}<\/p>\n<p>get_info(&#8216;mail@mail.com&#8217;,&#8217;password&#8217;);<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0445 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f:<br \/>\nCURLOPT_FOLLOWLOCATION, 1 &#8211; \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0435\u0441\u043b\u0438 PHP \u0432 \u043d\u0435\u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0438 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 open_basedir. \u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u0434\u043b\u044f \u043f\u0435\u0447\u0435\u043d\u0435\u043a!<br \/>\n\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0435\u0447\u0435\u043d\u0435\u043a.<br \/>\n\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0443\u043f\u0430\u044f, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <strong>logout<\/strong> \u0438 \u0442.\u0434.<\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438:<br \/>\n<a href=\"http:\/\/xdan.ru\/avtorizacija-na-sajte-pri-pomoshhi-curl-php.html\">http:\/\/xdan.ru\/avtorizacija-na-sajte-pri-pomoshhi-curl-php.html<\/a><br \/>\n<a href=\"http:\/\/www.php.net\/manual\/ru\/book.curl.php\">http:\/\/www.php.net\/manual\/ru\/book.curl.php<\/a><br \/>\n<a href=\"http:\/\/www.php.net\/manual\/ru\/function.curl-setopt.php\">http:\/\/www.php.net\/manual\/ru\/function.curl-setopt.php<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430: \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. function get_info($email,$pass) { $ch = curl_init(); $url = &#8216;https:\/\/www.somesite.com\/login&#8217;; curl_setopt($ch, CURLOPT_URL, $url ); \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 curl_setopt($ch, CURLOPT_HEADER, 0); \/\/ \u043f\u0443\u0441\u0442\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0442\u043e \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u043b \u0441\u0435\u0440\u0432\u0435\u0440 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); \/\/ \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0437\u0430 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0430\u043c\u0438 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);\/\/ \u0442\u0430\u0439\u043c\u0430\u0443\u0442 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\/\/ \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[231],"tags":[174,173,14,11],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts\/400"}],"collection":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/comments?post=400"}],"version-history":[{"count":11,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts\/400\/revisions"}],"predecessor-version":[{"id":523,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/posts\/400\/revisions\/523"}],"wp:attachment":[{"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/media?parent=400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/categories?post=400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trichev.com\/blog\/wp-json\/wp\/v2\/tags?post=400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}