来自:http://phpweby.com/tutorials/php/35
PHP is not limited to outputting html. PHP can output images, pdf, javascript files, etc. Browsers determine what type of content is by analyzing the headers sent. In this tutorial I will present you with some examples of how to send headers. To send PHP header use the function header(). You must call this function before any output. Use the function headers_sent() to check whether the headers have been sent and output started.
301 moved permanently (redirect):
<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.example.com');
die();
?>
302 moved temporarily(redirect):
<?php
header('Location: http://www.example.com');
die();
?>
404 Page Not Found:
<?php
header('HTTP/1.1 404 Not Found');
?>
Service not avaliable:
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 60');
?>
CSS:
<?php
header('Content-Type: text/css');
?>
Javascript header:
<?php
header('Content-Type: application/javascript');
?>
Images:
For JPEG(jpg):
<?php
header('Content-Type: image/jpeg');
?>
For PNG:
<?php
header('Content-Type: image/png');
?>
For BMP:
<?php
header('Content-Type: image/bmp');
?>
PDF (output pdf with php):
<?php
header('Content-Type: application/pdf');
echo file_get_contents('filename.pdf');
?>
Cache (force browsers not to cache files):
<?php
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header ('Pragma: no-cache');
?>
Download dialog:
<?php
header('Content-Disposition: attachment; filename=' . urlencode($f));
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream');
header('Content-Type: application/download');
header('Content-Description: File Transfer');
header('Content-Length: ' . filesize($f));
echo file_get_contents($f);
?>
Authentication (force the browser to pop up a Username/Password input window) - only available when PHP is running as an Apache module:
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="The Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'If cancel is pressed this text shows';
die();
} else {
//always escape your data//
$user='user';
$pass='pass';
if($_SERVER['PHP_AUTH_USER']==$user && $_SERVER['PHP_AUTH_PW']==$pass){
echo 'Authorized';
}
}
?>
php header编码
header("Content-type: text/html; charset=utf-8");
分享到:
相关推荐
Simple 301 Redirects插件可以把你希望301重定向到其它页面或站点的URL全部集合并排成列表。如果你整准备把某个站点整合到WordPress,这个插件实在是相当实用,而且她不会破坏原有的URL结构。Simple 301 Redirects...
Exceeded 30 redirects 网上有许多解决的办法,但是本人试了很多种办法解决,但是都没成功(不是说他们的方法不行,只是不适合我),在这里我把我知道方法说一下 1.添加请求头 #requests带上自己浏览器信息的请求头,默认...
主要介绍了详解 Java Maximum redirects (100) exceeded的相关资料,需要的朋友可以参考下
# Check SOCKS4/SOCKS5/HTTP/HTTPS proxies with and without authentication. Format of proxies with authentication: proxy_user:proxy_pass@...# Download proxy lists from the web. # Customizable User Agent.
通过4个实验,验证命令ip redirects的作用。有抓包有真相!
在Shopware 6商店中管理301和302重定向。 该插件与PHP 7.4及更高版本兼容。 该插件已从分叉。 您是Redirects插件的满意用户吗? 请考虑给我们的项目一个 :star: 在Github上主角,或 。 :check_mark: 特征 301重新...
const redirects = require ( 'koa-redirects' ) const koa = require ( 'koa' ) const app = koa ( ) redirects ( app , { prefix : '/api/v2' , map : { 'auth' : 'http://some.com/api/oauth' } } ) // or /...
register ( [ { plugin : require ( 'hapi-redirects' ) , options : { log : true , log404 : true , // can match any valid hapi route specifier including route params and redirect to the specified value:...
follow-redirects提供的和方法的行为与在本机和模块上发现的方法相同,不同之处在于它们将无缝地跟随重定向。 const { http , https } = require ( 'follow-redirects' ) ; http . get ( 'http://bit.ly/900913' ,...
然后: npm install -- save apostrophe - redirects配置在app.js ,将该模块添加到您的配置中: // Other modules, then...'apostrophe-redirects' : { } 如果愿意,可以将默认状态代码更改为301 (永久重定向):...
设置属性:allow_redirects = True ,则head方式会自动解析重定向链接,requests.get()方法的allow_redirects默认为True,head方法默认为False url_string="https://******" r = requests.head(url_strin
Spree Redirects 添加了一个用于将旧 URL 重定向到新 URL 的接口。 当您用闪亮的新网站替换现有网站并希望避免断开的链接和破碎的心时。 为了更好地了解它的作用,只需按照下面的演示说明... 安装 通过将以下内容...
现在使用google搜索时,google默认是重定向的,这样造成有些网络即使未被屏蔽也无法访问,就是重定向导致的,有了这个小工具,就消除重定向了! 安装方法:打开chrome->工具,将该文件拖入这个页面就ok了
提供一个接口来设置从旧URL到新页面的重定向,如果您将站点合并在一起,则可以解析备用域,非常适合在启动具有URL更改的新站点时设置301重定向 安装 $ composer require iqnection/silverstripe-redirects $ ~public...
Nuxt Netlify 在您的Nuxt.js项目中为Netlify动态生成_headers和_redirects文件。 该模块支持为Netlify站点创建和规则:您可以轻松地从nuxt配置文件配置自定义标头,基本auth,重定向指令和重写规则。 用其他语言阅读...
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:wagtail_automatic_redirects-1.1.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
使用它来检查 301 重定向的结果。 入门 准备没有标题列的 .csv,第一列是 404 url,第二列是要重定向到的正确 url。 用法 $ redirect-checker redirects.csv domaintostripfromredirects....
PHP-API-AUTH 可以用作... 它在这里: : 要求PHP 7或更高版本安装上载“ auth.php ”并编辑文件底部的配置块: main([ 'default' => [ 'api.php' => [ 'secret' => 'someVeryLongPassPhraseChangeMe', 'redirects' => '...