[英]Php cURL SCRIPT_URL
I'm using cURL to get content of page from other site. 我正在使用cURL从其他站点获取页面内容。 When I open this page in my browser I have
$_SERVER['SCRIPT_URL'] = '/content/'
. 当我在浏览器中打开此页面时,我有
$_SERVER['SCRIPT_URL'] = '/content/'
。 But when I get this page with cURL i have $_SERVER['SCRIPT_URL'] = '/content/index.php'
. 但是当我使用cURL获取此页面时,我有
$_SERVER['SCRIPT_URL'] = '/content/index.php'
。
What request should I send to have same SCRIPT_URL
as in browser? 我应该发送什么请求以具有与浏览器中相同的
SCRIPT_URL
?
Here is my class to get page: 这是我上课的页面:
<?php
class CurlReader implements IReader
{
/**
* @var array
*/
protected $_lastResponseHeaders = null;
/**
* @param string $url
* @param array $context
* @return string
*/
public function read($url, array $context = null)
{
$this->_lastResponseHeaders = null;
$return = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this, 'readHeader'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING , 'gzip');
if (!empty($context['method'])) {
if (strtolower($context['method']) == 'post') {
curl_setopt($ch, CURLOPT_POST, true);
}
}
if (!empty($context['header'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array_map('trim', explode("\r", $context['header'])));
}
$return = curl_exec($ch);
if(curl_exec($ch) === false) {
throw new ReaderException(curl_error($ch));
}
curl_close($ch);
return $return;
}
/**
* @return array
*/
public function getHeaders()
{
return $this->_lastResponseHeaders;
}
/**
* @param array $headers
*/
protected function readHeader($curl, $header)
{
if (strpos($header, 'HTTP') !== false) {
preg_match("/\d{3}/i", $header, $matches);
$this->_lastResponseHeaders['Status'] = (int) $matches[0];
} elseif (($pos = strpos($header, ':')) !== false) {
$name = trim(substr($header, 0, $pos));
$value = trim(substr($header, $pos + 1));
$this->_lastResponseHeaders[$name] = $value;
}
return strlen($header);
}
}
Try $_SERVER["SCRIPT_FILENAME"]
尝试
$_SERVER["SCRIPT_FILENAME"]
http://php.net/manual/en/reserved.variables.server.php : http://php.net/manual/zh/reserved.variables.server.php :
'SCRIPT_FILENAME'
'SCRIPT_FILENAME'
The absolute pathname of the currently executing script.
当前正在执行的脚本的绝对路径名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.