我一直在使用get_meta_tags()和get_headers()PHP函数,并且需要在网站缓慢或无响应的情况下设置超时值.有谁知道怎么做?
在我目前的项目中,我有一个与主站点集成的购物车.现在我必须创建一些迷你站点来显示从主站点检索的数据.当用户点击迷你网站中的立即购买按钮时,它应该重定向到主购物车.但是当用户点击继续购物按钮时,应该将其发送回他正在浏览的迷你网站页面.这两个站点将分为两个不同的域名.我可以把他送回他浏览我们的页面吗?
request.getHeader("Referer")
Run Code Online (Sandbox Code Playgroud)
这将是2个不同的网络应用程序,因此将request.getHeader("Referer")帮助将他发送回他正在浏览的页面.
请给我一些建议.
我正在尝试制作一个PHP脚本,以尽快检查网站的HTTP状态.
我目前正在使用get_headers()并在来自mysql数据库的200个随机URL的循环中运行它.
检查所有200 - 平均需要2米48秒.
我能做些什么才能让它(更快)更快?
(我知道fsockopen - 它可以检查20多个200个站点上的端口80 - 但它与请求http状态代码不同,因为服务器可能在端口上响应 - 但可能没有正确加载网站等)
这是代码..
<?php
function get_httpcode($url) {
$headers = get_headers($url, 0);
// Return http status code
return substr($headers[0], 9, 3);
}
###
## Grab task and execute it
###
// Loop through task
while($data = mysql_fetch_assoc($sql)):
$result = get_httpcode('http://'.$data['url']);
echo $data['url'].' = '.$result.'<br/>';
endwhile;
?>
Run Code Online (Sandbox Code Playgroud) 我知道为curl设置用户代理很容易,但我的代码基于get_headers,默认情况下get_headers用户代理为空.谢谢你的帮助.
这是我的代码
$url = 'http://www.wikipedia.com'; // URL WITH HTTP
$hurl = str_replace("http", "https", $url); // URL WITH HTTPS
$urlheads = get_headers($url, 1);
$surlheads = get_headers($hurl, 1);
$urlx = false;
$surlx = false;
foreach ($urlheads as $name => $value)
{
if ($name === 'Location')
{
$urlx=$value;
}
else{
}
}
print_r($urlx);
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
Warning: get_headers(): Peer certificate CN=`*.wikipedia.org' did not match expected CN=`www.wikipedia.com' in....
Warning: get_headers(): Failed to enable crypto in....
Warning: get_headers(https://www.wikipedia.com): failed to open stream: operation failed in .....
Array ( …Run Code Online (Sandbox Code Playgroud) 为了检查URL是否是图像,我使用PHP函数get_headers。在正常情况下,它运行良好。
但是当我落后于代理服务器时,它将导致超时异常。我有同样的问题,file_put_contents但是我通过添加上下文参数解决了。但是,该get_headers函数没有类似的参数。
你知道该怎么办吗?
描述底部的工作解决方案!
我正在运行PHP 5.4,并试图获取URL列表的标题.
在大多数情况下,一切都运行良好,但有三个URL导致问题(可能更多,更广泛的测试).
'http://www.alealimay.com'
'http://www.thelovelist.net'
'http://www.bleedingcool.com'
Run Code Online (Sandbox Code Playgroud)
这三个站点在浏览器中都可以正常工作,并生成以下标头响应:
(来自Safari)
请注意,所有三个标头响应都是 Code = 200
但是通过PHP检索标头,使用get_headers...
stream_context_set_default(array('http' => array('method' => "HEAD")));
$headers = get_headers($url, 1);
stream_context_set_default(array('http' => array('method' => "GET")));
Run Code Online (Sandbox Code Playgroud)
...返回以下内容:
url ...... "http://www.alealimay.com"
headers
| 0 ............................ "HTTP/1.0 400 Bad Request"
| content-length ............... "378"
| X-Synthetic .................. "true"
| expires ...................... "Thu, 01 Jan 1970 00:00:00 UTC"
| pragma ....................... "no-cache"
| cache-control ................ "no-cache, must-revalidate"
| content-type ................. "text/html; charset=UTF-8"
| connection ................... "close"
| date ......................... …Run Code Online (Sandbox Code Playgroud) 这是网址: https: //www.grammarly.com
我正在尝试使用本机函数获取 HTTP 标头get_headers():
$headers = get_headers('https://www.grammarly.com')
Run Code Online (Sandbox Code Playgroud)
结果是
HTTP/1.1 400 Bad Request
Date: Fri, 27 Apr 2018 12:32:34 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 52
Connection: close
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用命令行工具执行相同的操作curl,结果会有所不同:
curl -sI https://www.grammarly.com/
HTTP/1.1 200 OK
Date: Fri, 27 Apr 2018 12:54:47 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 25130
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)
造成这种反应差异的原因是什么?这是 Grammarly 的服务器端某种实施不力的安全功能还是其他什么?
在PHP中,我使用的get_meta_tags()和get_headers(),但是,当有一个404,这两个函数抛出一个警告.有什么办法让我抓住它吗?谢谢!
如何使用php get_headers只获取位置部分?
var_dump(get_headers('http://www.google.com',1));
Run Code Online (Sandbox Code Playgroud)
这个回报:
array(12) { [0]=> string(18) "HTTP/1.0 302 Found" ["Location"]=> string(21) "http://www.google.it/" ... }
Run Code Online (Sandbox Code Playgroud)
然后我用
echo (get_headers('http://www.google.com',1)["Location"];
Run Code Online (Sandbox Code Playgroud)
错误:Parse error: syntax error, unexpected '['在这一echo行
我想检查外部URL是否存在,并且我尝试使用不同的功能.大多数函数使用get_headers()函数,这总是向我显示警告"警告:get_headers()[function.get-headers]:此函数只能用于/ myhosting/...中的URL".可能是什么原因导致这不起作用?本地主机,Mac与MAMP
我似乎无法找到一种方法来访问响应标题中的 X-WP-TotalPages,我能够以我想要的方式显示我的订单和所有内容,但对于我的生活,我无法弄清楚如何到达响应中的标头。
我现在正在使用它;
require($_SERVER["DOCUMENT_ROOT"] . "/vendor/autoload.php");
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'http://example.com',
'**********************************',
'**********************************',
[
'wp_api' => true,
'version' => 'wc/v1',
]
);
$endpoint = 'orders';
$options = ['filter[limit]' => '200', 'filter[period]' => 'year', 'filter[order]' => 'ASC', 'status' => 'processing'];
$result = $woocommerce->get($endpoint, $options);
Run Code Online (Sandbox Code Playgroud)
我很确定我需要类似的东西;
print_r(get_headers($result['X-WP-TotalPages']));
Run Code Online (Sandbox Code Playgroud)
我尝试了许多不同的变体,但似乎无法弄清楚,任何帮助将不胜感激!
我正在尝试通过研究一些免费插件/主题来学习 WordPress 结构。
我现在正在研究“Renger博客主题”,但我无法理解一些东西。我已经检查了WP 手册中的get_header () 页面,但它看起来仍然很神奇:)
该主题有自定义功能代码
wordpress\wp-content\themes\renderblog\inc\renderoption.php
Run Code Online (Sandbox Code Playgroud)
这个主题只用调用这个文件
get_header();
Run Code Online (Sandbox Code Playgroud)
在index.php中
header.php中没有包含代码。
它是如何调用这个特定的 PHP 文件的get_header()?这是否是一种自动包含 inc 文件夹中所有文件的方法?
当我刚刚get_header()从index.php 中删除时,这些功能不起作用。