A
A
Andrew2014-01-27 17:21:45
PHP
Andrew, 2014-01-27 17:21:45

Translation of code from python to php?

Please help me to translate this code:

import urllib2, urllib, time, cookielib

cookies = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies))
urllib2.install_opener(opener)

header = {'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9b4) Gecko/2008030318 Firefox/3.0b4'}
data = urllib.urlencode({"login" : "login", "pass" : "pass", "LOGIN_redirect" : "1", "lreseted" : "1", "preseted" : "1"})
request = urllib2.Request("http://site.com/login.php", data, header)
response = urllib2.urlopen(request)


The moment of translation is not clear - sending a POST request to the site.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2014-01-27
@mayken

curl

D
DuD, 2014-01-28
@DuD

$cookies = 'my_cookies.txt'; //путь к файлу с куками
$url = 'http://site.com/login.php';
$post = ;//сюда данные POST запроса
$useragent = 'Opera/9.25 (Windows NT 6.0; U; ru)';
     
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question