Ⅰ php header頭文件寫在哪在html文件里還是在哪裡
你說的header頭文件是只網頁布局的header部分么?理論上來說,如果全靜態的話,放在html裡面也可以。但是通常是放在php文件里的,裡面也包含html內容,因為這部分通常會輸出一些動態內容,如用戶名等等。
Ⅱ php 獲取網頁頭部信息和網頁和網頁源代碼查看
<?php
/**
* http下載類庫
*/
class Httplib{
// 目標網站無法打開時返回的錯誤代碼
var $_ERROR_CONNECT_FAILURE = 600;
// 自定義 UserAgent 字元串
var $_SEND_USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; LazyCMS.net::DownLoader)';
var $_url,$_method,$_timeout;
var $_scheme,$_host,$_port,$_path,$_query,$_referer;
var $_header;
var $_response;
/**
* 兼容PHP5模式
*
* @param 同下面的參數
*/
function __construct($url=null,$method='GET',$timeout=60){
@set_time_limit(0);
if (!empty($url)) {
$this->connect($url,$method,$timeout);
}
return $this;
}
/**
* 初始化對象
*
* @param string $url
* @param string $method
* @param int $timeout
* @return object
*/
function Httplib($url=null,$method='GET',$timeout=60){
return $this->__construct($url,$method,$timeout);
}
/**
* 改變連接url
*
* @param string $url
* @param string $method
* @param int $timeout
* @return object
*/
function connect($url=null,$method='GET',$timeout=60){
$this->_header = null;
$this->_response = null;
$this->_url = $url;
$this->_method = strtoupper(empty($method) ? 'GET' : $method);
$this->_timeout = empty($timeout) ? 30 : $timeout;
if (!empty($url)) {
$this->_parseURL($url);
}
return $this;
}
/**
* 發送請求
*
* @param array $params
* @return bool
*/
function send($params=array()) {
$header = null; $response = null; $QueryStr = null;
if (!empty($params)) { $this->_method = 'POST'; }
if (function_exists('fsockopen')) {
$fp = @fsockopen($this->_host,$this->_port,$errno,$errstr,$this->_timeout);
if (!$fp) { return false; }
$_port = ((int)$this->_port!==80) ? ':'.$this->_port : null;
$SendStr = "{$this->_method} {$this->_path}{$this->_query} HTTP/1.0\r\n";
$SendStr.= "Host:{$this->_host}{$_port}\r\n";
$SendStr.= "Accept: */*\r\n";
$SendStr.= "Referer:{$this->_referer}\r\n";
$SendStr.= "User-Agent: ".$this->_SEND_USER_AGENT."\r\n";
$SendStr.= "Pragma: no-cache\r\n";
$SendStr.= "Cache-Control: no-cache\r\n";
//如果是POST方法,分析參數
if ($this->_method=='POST') {
//判斷參數是否是數組,循環出查詢字元串
if (is_array($params)) {
$QueryStr = http_build_query($params);
} else {
$QueryStr = $params;
}
$length = strlen($QueryStr);
$SendStr.= "Content-Type: application/x-www-form-urlencoded\r\n";
$SendStr.= "Content-Length: {$length}\r\n";
}
$SendStr.= "Connection: Close\r\n\r\n";
if(strlen($QueryStr) > 0){
$SendStr.= $QueryStr."\r\n";
}
fputs($fp,$SendStr);
// 讀取 header
do{ $header.= fread($fp,1); } while (!preg_match("/\r\n\r\n$/",$header));
// 遇到跳轉,執行跟蹤跳轉
if ($this->_redirect($header)) { return true; }
// 讀取內容
while(!feof($fp)) {
$response.= fread($fp,4096);
}
fclose($fp);
} elseif (function_exists('curl_exec')) {
$ch = curl_init($this->_url);
curl_setopt_array($ch,array(
CURLOPT_TIMEOUT => $this->_timeout,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => $this->_SEND_USER_AGENT,
CURLOPT_REFERER => $this->_referer,
));
if ($this->_method=='GET') {
curl_setopt($ch,CURLOPT_HTTPGET,true);
} else {
if (is_array($params)) {
$QueryStr = http_build_query($params);
} else {
$QueryStr = $params;
}
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$QueryStr);
}
$fp = curl_exec($ch);
curl_close($ch);
if (!$fp) { return false; }
$i = 0; $length = strlen($fp);
// 讀取 header
do{ $header.= substr($fp,$i,1); $i++; } while (!preg_match("/\r\n\r\n$/",$header));
// 遇到跳轉,執行跟蹤跳轉
if ($this->_redirect($header)) { return true; }
// 讀取內容
do {
$response.= substr($fp,$i,4096);
$i = $i + 4096;
} while ($length>=$i);
unset($fp,$length,$i);
}
$this->_header = $header;
$this->_response = $response;
return true;
}
/**
* 跟蹤跳轉
*
* @param string $header
* @return bool
*/
function _redirect($header){
if (in_array($this->status($header),array(301,302))) {
if(preg_match("/Location\:(.+)\r\n/i",$header,$regs)){
$this->connect(trim($regs[1]),$this->_method,$this->_timeout);
$this->send();
return true;
}
} else {
return false;
}
}
/**
* 取得請求的header
*
* @return string
*/
function header(){
return $this->_header;
}
/**
* 請求返回的html
*
* @return string
*/
function response(){
return $this->_response;
}
/**
* 返回狀態
*
* @param string $header
* @return int
*/
function status($header=null){
if (empty($header)) {
$header = $this->_header;
}
if(preg_match("/(.+) (\d+) (.+)\r\n/i",$header,$status)){
return $status[2];
} else {
return $this->_ERROR_CONNECT_FAILURE;
}
}
/**
* 解析url
*
* @param string $url
*/
function _parseURL($url){
$aUrl = parse_url($url);
$aUrl['query'] = isset($aUrl['query']) ? $aUrl['query'] : null;
$scheme = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : null;
$this->_scheme = ($scheme=='off' || empty($scheme)) ? 'http' : 'https';
$this->_host = isset($aUrl['host']) ? $aUrl['host'] : null;
$this->_port = empty($aUrl['port']) ? 80 : (int)$aUrl['host'];
$this->_path = empty($aUrl['path']) ? '/' : (string)$aUrl['path'];
$this->_query = strlen($aUrl['query']) > 0 ? '?'.$aUrl['query'] : null;
$this->_referer = $this->_scheme.'://'.$aUrl['host'];
}
}
$http = new Httplib('http://www..com');
$http->send();
$body = $http->response();
echo $body;
Ⅲ 求PHP頁面固定區域的列印代碼
提交後,出現列印鏈接,鏈接是打開一個新窗口,新窗口可以設為無地址欄。
這樣點了提交按鈕後,你要做一個PHP程序,把上面你所需要列印的內容重新顯示。然後上面顯示「列印」按鈕,在新頁面中用列印功能,這樣比較理想吧,沒有網址什麼的。也很乾凈,很簡單。
你可能希望用一段javascript代碼,實現網頁局部列印吧?給你看看下面例子:
<script language="javascript">
function preview()
{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
<div>文件頭部,不列印出來的內容。。。</div>
<div>文件頭部,不列印出來的內容。。。</div>
<div>文件頭部,不列印出來的內容。。。</div>
<!--startprint-->
<div>這是被列印出來的內容</div>
<div>這是被列印出來的內容</div>
<div>這是被列印出來的內容</div>
<div>這是被列印出來的內容</div>
<!--endprint-->
<div>文件尾部,不列印出來的內容。。。</div>
<div>文件尾部,不列印出來的內容。。。</div>
<div>文件尾部,不列印出來的內容。。。</div>
<input type="button" name="print" value="預覽並列印" onclick="preview()">
Ⅳ ecshop修改了一個list_goods.php後,怎麼列印數組,查看調試,具體一些
以下代碼可以幫助你調試程序:
echo "<pre>";
print_r($test);
echo "<pre>";
$test就是你要列印的數組,然後找display對應的模板,頁面頭部就可以看到你數組的數據。
希望能幫助到你..
Ⅳ php頁面如何引入通用的頭部與底部或者相同的邊欄
用include或者require。
語法:include '文件';
require '文件';
至於它們的區別:require 會生成致命錯誤(E_COMPILE_ERROR)並停止腳本。include 只生成警告(E_WARNING),並且腳本會繼續。
Ⅵ 如何用php設置utf-8編碼
在你的源文件找到<meta http-equiv="content-type" content="text/html;charset=utf-8">charset= 後面接的就是編碼,你全部改了就可以了。如果你改了之後變成亂碼的話,那你就只能先建一個utf-8編碼的網頁,把相應的內容重新輸入進去。
Ⅶ php如何在header()函數之前輸出內容
PHP 中 header()函數的作用是給客戶端發送頭信息。
什麼是頭信息?
這里只作簡單解釋,詳細的自己看http協議。
在 HTTP協議中,伺服器端的回答(response)內容包括兩部分:頭信息(header) 和 體內容,這里的頭信息不是HTML中的<head></head>部分,同樣,體內容也不是<BODY>< /BODY>。頭信息是用戶看不見的,裡麵包含了很多項,包括:伺服器信息、日期、內容的長度等。而體內容就是整個HTML,也就是你所能看見的全 部東西。
頭信息有什麼用呢?
頭信息的作用很多,最主要的有下面幾個:
1、跳轉:當瀏覽器接受到頭信息中的 Location: xxxx 後,就會自動跳轉到 xxxx 指向的URL地址,這點有點類似用 js 寫跳轉。但是這個跳轉只有瀏覽器知道,不管體內容里有沒有東西,用戶都看不到。
2、指定網頁的內容: 同樣一個XML文件,如果頭信息中指定:Content-type: application/xml 的話,瀏覽器會將其按照XML文件格式解析。但是,如果頭信息中是:Content-type: text/xml 的話,瀏覽器就會將其看作存文本解析。(瀏覽器不是按照擴展名解析文件的)
不知道大家有沒有注意,有些時候在一些網站下載東西,點下載連接以後,結果瀏覽器將這個附件當成網頁打開 了,裡面顯示的都是亂碼,這個問題也和頭信息有關。有時候瀏覽器根據Content-type 來判斷是打開還是保存,這樣有時就會判斷錯誤(主要是網站設計者忘記寫Content-type)。其實,還有一個可以來指定該內容為附件、需要保存,這 個就是:Content-Disposition: attachment; filename="xxxxx"
// 指定內容為附件
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// 打開文件,並輸出
readfile('original.pdf');
Ⅷ php怎樣調用公共網頁頭部及尾部 謝謝!
新建一個頭部文件header.php,寫入:
<?phpecho"頭部載入成功<br/>";?>
載入文件時只要
<?php
include'./Public/header.php';
echo'顯示測試';
include'./Public/footer.php';
?>
Ⅸ php輸出圖片無法顯示,文件頭部有空白
你在第2種方式里,除了 img 輸出外,還有其它輸出。
請參看下面的示例代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?<a href="https://www..com/s?wd=php&tn=44039180_cpr&fenlei=_5y9YIZ0lQzqlpA-" target="_blank" class="-highlight">php</a>
// 創建新的圖像實例
$<a href="https://www..com/s?wd=im&tn=44039180_cpr&fenlei=_5y9YIZ0lQzqlpA-" target="_blank" class="-highlight">im</a> = <a href="https://www..com/s?wd=im&tn=44039180_cpr&fenlei=_5y9YIZ0lQzqlpA-" target="_blank" class="-highlight">im</a>agecreatetruecolor(100, 100);
// 設置背景為白色
imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);
//在圖像上寫字
imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);
//echo "這一行如果加上就不能正常顯示下面的圖像了。";
// 輸出圖像到瀏覽器
header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
?>
為什麼第 2 種方式,不能在header前面有內容,究其原因,請參看以下說明:
header()必須在任何實際輸出之前調用,不管是普通的html標簽,還是文件裡面的空行、空格或者是PHP文件里的空行、空格。
簡單一句話:在header()被調用之前有輸出就會出錯。
Ⅹ PHP 如何保存/列印 整個Http請求頭和附帶的post數據
同求,知道的大神解答一下