Не работает CURLOPT HTTPHEADER

Хочу эмулировать ajax запрос, делаю так
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .php.geshi_code {font-family:monospace;} .php.geshi_code .imp {font-weight: bold; color: red;} .php.geshi_code .kw1 {color: #b1b100;} .php.geshi_code .kw2 {color: #000000; font-weight: bold;} .php.geshi_code .kw3 {color: #990000;} .php.geshi_code .co1 {color: #666666; font-style: italic;} .php.geshi_code .co2 {color: #666666; font-style: italic;} .php.geshi_code .co3 {color: #0000cc; font-style: italic;} .php.geshi_code .co4 {color: #009933; font-style: italic;} .php.geshi_code .coMULTI {color: #666666; font-style: italic;} .php.geshi_code .es0 {color: #000099; font-weight: bold;} .php.geshi_code .es1 {color: #000099; font-weight: bold;} .php.geshi_code .es2 {color: #660099; font-weight: bold;} .php.geshi_code .es3 {color: #660099; font-weight: bold;} .php.geshi_code .es4 {color: #006699; font-weight: bold;} .php.geshi_code .es5 {color: #006699; font-weight: bold; font-style: italic;} .php.geshi_code .es6 {color: #009933; font-weight: bold;} .php.geshi_code .es_h {color: #000099; font-weight: bold;} .php.geshi_code .br0 {color: #009900;} .php.geshi_code .sy0 {color: #339933;} .php.geshi_code .sy1 {color: #000000; font-weight: bold;} .php.geshi_code .st0 {color: #0000ff;} .php.geshi_code .st_h {color: #0000ff;} .php.geshi_code .nu0 {color: #cc66cc;} .php.geshi_code .nu8 {color: #208080;} .php.geshi_code .nu12 {color: #208080;} .php.geshi_code .nu19 {color:#800080;} .php.geshi_code .me1 {color: #004000;} .php.geshi_code .me2 {color: #004000;} .php.geshi_code .re0 {color: #000088;} .php.geshi_code span.xtra { display:block; }

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://xdan.ru/ip/?all&headers' );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'dddd'=>'gfhfgh',
    "User-Agent" => "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
    "X-Requested-With" => "XMLHttpRequest",
    "Referer" => "http://someloginserver.com/sendlogin.php"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвратить то что вернул сервер
$data = curl_exec($ch);
curl_close($ch);
exit($data);
 

на сервере простецкий код
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .php.geshi_code {font-family:monospace;} .php.geshi_code .imp {font-weight: bold; color: red;} .php.geshi_code .kw1 {color: #b1b100;} .php.geshi_code .kw2 {color: #000000; font-weight: bold;} .php.geshi_code .kw3 {color: #990000;} .php.geshi_code .co1 {color: #666666; font-style: italic;} .php.geshi_code .co2 {color: #666666; font-style: italic;} .php.geshi_code .co3 {color: #0000cc; font-style: italic;} .php.geshi_code .co4 {color: #009933; font-style: italic;} .php.geshi_code .coMULTI {color: #666666; font-style: italic;} .php.geshi_code .es0 {color: #000099; font-weight: bold;} .php.geshi_code .es1 {color: #000099; font-weight: bold;} .php.geshi_code .es2 {color: #660099; font-weight: bold;} .php.geshi_code .es3 {color: #660099; font-weight: bold;} .php.geshi_code .es4 {color: #006699; font-weight: bold;} .php.geshi_code .es5 {color: #006699; font-weight: bold; font-style: italic;} .php.geshi_code .es6 {color: #009933; font-weight: bold;} .php.geshi_code .es_h {color: #000099; font-weight: bold;} .php.geshi_code .br0 {color: #009900;} .php.geshi_code .sy0 {color: #339933;} .php.geshi_code .sy1 {color: #000000; font-weight: bold;} .php.geshi_code .st0 {color: #0000ff;} .php.geshi_code .st_h {color: #0000ff;} .php.geshi_code .nu0 {color: #cc66cc;} .php.geshi_code .nu8 {color: #208080;} .php.geshi_code .nu12 {color: #208080;} .php.geshi_code .nu19 {color:#800080;} .php.geshi_code .me1 {color: #004000;} .php.geshi_code .me2 {color: #004000;} .php.geshi_code .re0 {color: #000088;} .php.geshi_code span.xtra { display:block; }

<?php
foreach($_SERVER as $key=>$val){
  if(isset($_GET['all']) or preg_match('#^[0-9.]+$#',$val))
    echo $key.'='.$val."n<br/>";
}
if(isset($_GET['headers'])){
 var_export(apache_request_headers());
}
 

В результате запроса вижу это
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .html4strict.geshi_code {font-family:monospace;} .html4strict.geshi_code .imp {font-weight: bold; color: red;} .html4strict.geshi_code .kw2 {color: #000000; font-weight: bold;} .html4strict.geshi_code .kw3 {color: #000066;} .html4strict.geshi_code .es0 {color: #000099; font-weight: bold;} .html4strict.geshi_code .br0 {color: #66cc66;} .html4strict.geshi_code .sy0 {color: #66cc66;} .html4strict.geshi_code .st0 {color: #ff0000;} .html4strict.geshi_code .nu0 {color: #cc66cc;} .html4strict.geshi_code .sc-1 {color: #808080; font-style: italic;} .html4strict.geshi_code .sc0 {color: #00bbdd;} .html4strict.geshi_code .sc1 {color: #ddbb00;} .html4strict.geshi_code .sc2 {color: #009900;} .html4strict.geshi_code span.xtra { display:block; }

SCRIPT_URL=/ip/
SCRIPT_URI=http://xdan.ru/ip/
HTTP_CGI_AUTHORIZATION=
HTTP_HOST=xdan.ru
HTTP_X_REAL_IP=-----------
HTTP_CONNECTION=close
HTTP_ACCEPT=*/*
HTTP_HTTP=//someloginserver.com/sendlogin.php
PATH=/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/bin:/sbin:/mnt/portal/bin
SERVER_SIGNATURE=
SERVER_SOFTWARE=Apache/2.0.63-lk.e (Unix) mod_ssl/2.0.63-lk.e OpenSSL/0.9.8k mod_dp20/0.99.2 PHP/5.3.10 mod_python/3.3.1 Python/2.6.2 mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_wsgi/3.3
SERVER_NAME=xdan.ru
SERVER_ADDR=----------
SERVER_PORT=80
REMOTE_ADDR=92.50.156.138
DOCUMENT_ROOT=/home/x/xdanru/public_html
SERVER_ADMIN=root@sweb.ru
SCRIPT_FILENAME=/home/x/xdanru/public_html/ip/index.php
REMOTE_PORT=51863
GATEWAY_INTERFACE=CGI/1.1
SERVER_PROTOCOL=HTTP/1.0
REQUEST_METHOD=GET
QUERY_STRING=all&headers
REQUEST_URI=/ip/?all&headers
SCRIPT_NAME=/ip/index.php
PHP_SELF=/ip/index.php
REQUEST_TIME=1354618285
argv=Array
argc=1
array ( 'Host' => 'xdan.ru', 'X-Real-IP' => '----------', 'Connection' => 'close', 'Accept' => '*/*', 'http' => '//someloginserver.com/sendlogin.php', )
 

ни тебе user агента, ни то что это ajax запрос

1 ответов


Это потому, что вы устанавливаете заголовки не верно, нужно вот так:


curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'dddd: gfhfgh',
        "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
        "X-Requested-With: XMLHttpRequest",
        "Referer: http://someloginserver.com/sendlogin.php"
));
 
Смотрите в документации