當前位置:首頁 » 編程語言 » phpauthorization

phpauthorization

發布時間: 2022-06-12 19:36:30

1. 一個php 文件與多個html文件如何進行交互

<?php

header("Content-type: text/html; charset=gb2312");

header("Pragma: no-cache");

header("Expires: 0");

@$action = $_REQUEST ['action'];

$sid = MyTool::generateId ();

if (! $action)

$action = "list";

Trace::debug ( $action );


if ($action == "save") {

$reply = $_REQUEST ['reply'];//獲取回復值

print_r($reply);

$id = $_REQUEST ['f_id'];

CourseService::updateApplyState($db,$id,TrainApply::STATUS_PASS);


$apply=CourseService::getTrainApply($db,$id);


$student=$apply->owner;

$trainId=$apply->train;


$train=CourseService::getTrainSchele($db,$trainId);


$pass_test=$train->test==""?0:-1;

$pass_judge=$train->judge==""?0:-1;

$pass_readrate=$train->readrate==""?0:-1;

$pass_feedback=$train->feedback==""?0:-1;


$mc = new MyCourse();

$mc->schele_id = $train->id;

$mc->course_id = $train->course_id;

$mc->user_id = $student;

$mc->type = $train->catalog;

$mc->state = MyCourse::STATE_WAITING;

$mc->pass_test = $pass_test;

$mc->pass_judge =$pass_judge ;

$mc->pass_feedback = $pass_feedback;

$mc->pass_readrate = $pass_readrate;

$mc->score = $train->score;

$mc->starttime = $train->starttime;

$mc->endtime = $train->endtime;

$mc->coursename = $train->name;

CourseService::save($db, $mc);


print"<script>alert('通過操作成功!');window.close();location.href='applyreply.php?action=list'</script>";

}

if ($action == "reject") {

$id = $_REQUEST ['f_id'];

$sql = "update t_train_apply set f_status=2 where f_id='".$id."'";

Trace::debug ( $sql );

$db->Execute ( $sql );

print"<script>alert('拒絕操作成功!');window.close();location.href='applyreply.php?action=list'</script>";

}

if ($action == "list") {

$pagination = new MyPagination(0,1);

$UserID = $_SESSION[AuthorizationHelper::SESSION_USER_KEY]['id'];

$as = CourseService::listApply($db,$pagination,null,null,null,$UserID);

//print_r($as);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>無標題文檔</title>


<?= HTMLTool::includeResource() ?>

<link href="../css/css.css" rel="stylesheet" type="text/css" />

<script language="JavaScript">

$(function() {

$('#tabs').tabs({spinner:'載入...',fx:{ opacity: 'toggle' },selected:2});

});

function passIt(id){

var url = '<?php print $_SERVER['PHP_SELF'] ?>';

var pars = 'action=pass&f_id='+id;

alert(url+"?"+pars);

// open(url+"?"+pars);

var myAjax = new Ajax.Request(

url,

{

method: 'get',

parameters: pars,

onComplete:done

});

afterPass(id);

}


function afterPass(id){

// alert(originalRequest.responseXML);

// var result = originalRequest.responseXML.getElementsByTagName("id");

// alert(result.length);

document.getElementById('button_'+id).style.display='none';

document.getElementById('status_'+id).innerHTML='通過';

}

function rejectIt(id){

var url = '<?php print $_SERVER['PHP_SELF'] ?>';

var pars = 'action=reject&f_id='+id;

//alert(url+"?"+pars);

var myAjax = new Ajax.Request(

url,

{

method: 'get',

parameters: pars,

onComplete:done

});

afterReject(id);

}


function afterReject(id){

// alert(originalRequest.responseXML);

// var result = originalRequest.responseXML.getElementsByTagName("id");

// alert(result.length);

document.getElementById('button_'+id).style.display="none";

document.getElementById('status_'+id).innerHTML="駁回";

}


function done(){

alert("操作成功");

}

</script>

</head>


<body >

<!-- 導航欄 -->

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="navigationbar" class="navigationbar">

<tr><td height="28" >您現在的位置: <a href="../welcom.php">首頁</a> >> <a href="#">考試管理</a> >>考試申請管理</td></tr>

</table>

<table width="98%" border="0" cellpadding="0" cellspacing="0" align="center">

<tr>

<td valign="top">

<table width="100%" border="0" cellpadding="1" cellspacing="1" class="listtable">

<thead>

<tr>

<td width="150">考試名稱</td>

<td>申請原因</td>

<td width="150">申請人</td>

<td width="130">申請時間</td>

<td width="80">狀態</td>

<td width="80">管理</td>

</tr>

</thead>

<?php

//foreach($as as $a){

//Trace::debug($a);

//$schele = CourseService::getTrainSchele($db,$a->train);

//$u = UserService::getUser($db,$a->owner);

?>

<tr>

<td><?= $schele->name ?></td>

<td><?= $a->name ?></td>

<td><?= $u->trueName ?></td>

<td><?= MyTool::formatDate($a->createtime)?></td>

<td><span id="status_<?= $a->id ?>"><?= TrainApply::$STATUS_ARRAY[$a->status]?></span></td>

<td>&nbsp;<span id="button_<?= $a->id ?>">

<?php if($a->status==TrainApply::STATUS_WAITING) {?>

<a href="?action=pass&f_id=<?= $a->id ?>">通過</a>&nbsp;

<a href="application_manage.php?action=reject&f_id=<?= $a->id ?>">拒絕</a>

<?php } ?>

</td>

</tr>

<?php //} ?>

</table>

<?php include($_SERVER['DOCUMENT_ROOT']."/train/common/pagination.php")?>

</td>

</tr>

</table>


</body>

</html>

<?php }?>

<?php if($action=="pass") {//回復

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>無標題文檔</title>


<?= HTMLTool::includeResource() ?>

<script >

$(document).ready(function(){

$("#commonForm").validate();

});

</script>

</head>


<body>


<table width="98%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td class="border_left_up"></td>

<td class="border_middle_up"><span class="pagetitle">建議回復</span></td>

<td class="border_right_up"></td>

</tr>

</table>

</td>

</tr>

<tr>

<td align="center">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td class="border_left_middle">&nbsp;</td>

<td align="center">

<form id="commonForm" method="post">

<input type="hidden" name="action" value="save"/>

<input type="hidden" name="id" value="<?php print $_REQUEST ['id']?>" />

<textarea class="required" rows="10" cols="120" name="reply" maxlength="500">您的建議已採納,謝謝參與</textarea><br>

<span class="btn_green"><span><button type="submit" id="sure">提 交</button></span></span>

</form>

</td>

<td class="border_right_middle">&nbsp;</td>

</tr>

</table>

</td>

</tr>

<tr>

<td><table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td class="border_left_down"></td>

<td class="border_middle_down">&nbsp;</td>

<td class="border_right_down"></td>

</tr>

</table></td>

</tr>

</table>

</body>

</html>


<?php } ?>


  • 就是你要的效果,,看仔細點只看標簽與判斷就行

2. PHP通過微信跳轉的Code參數獲取用戶的openid(關鍵代碼)

關鍵代碼如下所示:
//獲取微信登錄用戶信息
function
getOpenID($appid,$appsecret,$code){
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".
$appsecret."&code=".$code."&grant_type=authorization_code";
$weixin=file_get_contents($url);//通過code換取網頁授權access_token
$jsondecode=json_decode($weixin);
//對JSON格式的字元串進行編碼
$array
=
get_object_vars($jsondecode);//轉換成數組
$openid
=
$array['openid'];//輸出openid
return
$openid;
}
以上所述是小編給大家介紹的PHP通過微信跳轉的Code參數獲取用戶的openid(關鍵代碼),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

3. Authorization Error是怎麼回事啊老師

語法錯誤
在/tmp/smarty/(中文文件名的文件夾)/list.tpl.php文件的20行出現了T_ELSEIF,無法識別
看看是不是拼寫錯誤,另外檢查一下周邊的語法

4. jsp中request.getHeader()獲取客戶端的各種信息,那php中什麼方法來獲取

伺服器變數 $_SERVER 詳解:

1、$_SESSION['PHP_SELF'] -- 獲取當前正在執行腳本的文件名

2、$_SERVER['SERVER_PROTOCOL'] -- 請求頁面時通信協議的名稱和版本。例如,「HTTP/1.0」。

3、$_SERVER['REQUEST_TIME'] -- 請求開始時的時間戳。從 PHP 5.1.0 起有效。和time函數效果一樣。

4、$_SERVER['argv'] -- 傳遞給該腳本的參數。我試了下,get方法可以得到$_SERVER['argv'][0];post方法無法給他賦值。

5、$_SERVER['SERVER_NAME'] -- 返回當前主機名。

6、$_SERVER['SERVER_SOFTWARE'] -- 伺服器標識的字串,在響應請求時的頭信息中給出。 如Microsoft-IIS/6.0

7、$_SERVER['REQUEST_METHOD'] -- 訪問頁面時的請求方法。例如:「GET」、「HEAD」,「POST」,「PUT」。

8、$_SERVER['QUERY_STRING'] -- 查詢(query)的字元串(URL 中第一個問號 ? 之後的內容)。

9、$_SERVER['DOCUMENT_ROOT'] -- 當前運行腳本所在的文檔根目錄。在伺服器配置文件中定義。 如E:\server

10、$_SERVER['HTTP_ACCEPT'] -- 當前請求的 Accept: 頭信息的內容。

11、$_SERVER['HTTP_ACCEPT_CHARSET'] -- 當前請求的 Accept-Charset: 頭信息的內容。例如:「iso-8859-1,*,utf-8」。

12、$_SERVER['HTTP_ACCEPT_ENCODING'] -- 當前請求的 Accept-Encoding: 頭信息的內容。例如:「gzip」。

13、$_SERVER['HTTP_ACCEPT_LANGUAGE'] -- 當前請求的 Accept-Language: 頭信息的內容。例如:「en」。

14、$_SERVER['HTTP_CONNECTION'] -- 當前請求的 Connection: 頭信息的內容。例如:「Keep-Alive」。

15、$_SERVER['HTTP_HOST'] -- 當前請求的 Host: 頭信息的內容。

16、$_SERVER['HTTP_REFERER'] -- 鏈接到當前頁面的前一頁面的 URL 地址。

17、$_SERVER['HTTP_USER_AGENT'] -- 返回用戶使用的瀏覽器信息。也可以使用 get_browser() 得到此信息。

18、$_SERVER['HTTPS'] -- 如果通過https訪問,則被設為一個非空的值,否則返回off.

19、$_SERVER['REMOTE_ADDR'] -- 正在瀏覽當前頁面用戶的 IP 地址。

20、$_SERVER['REMOTE_HOST'] -- 正在瀏覽當前頁面用戶的主機名。反向域名解析基於該用戶的 REMOTE_ADDR。如本地測試返回127.0.0.1

21、$_SERVER['REMOTE_PORT'] -- 用戶連接到伺服器時所使用的埠。我在本機測試沒通過,不知道什麼原因。

22、$_SERVER['SCRIPT_FILENAME'] -- 當前執行腳本的絕對路徑名。如返回E:\server\index.php

23、$_SERVER['SERVER_ADMIN'] -- 該值指明了 Apache 伺服器配置文件中的 SERVER_ADMIN 參數。如果腳本運行在一個虛擬主機上,則該值是那個虛擬主機的值

24、$_SERVER['SERVER_PORT'] -- 伺服器所使用的埠。默認為「80」。如果使用 SSL 安全連接,則這個值為用戶設置的 HTTP 埠。

25、$_SERVER['SERVER_SIGNATURE'] -- 包含伺服器版本和虛擬主機名的字元串。

26、$_SERVER['PATH_TRANSLATED'] -- 當前腳本所在文件系統(不是文檔根目錄)的基本路徑。這是在伺服器進行虛擬到真實路徑的映像後的結果。 Apache 2 用 戶可以使用 httpd.conf 中的 AcceptPathInfo On 來定義 PATH_INFO。

27、$_SERVER['SCRIPT_NAME'] -- 包含當前腳本的路徑。這在頁面需要指向自己時非常有用。__FILE__ 包含當前文件的絕對路徑和文件名(例如包含文件)。

28、$_SERVER['REQUEST_URI'] -- 訪問此頁面所需的 URI。例如,「/index.html」。

29、$_SERVER['PHP_AUTH_DIGEST'] -- 當作為 Apache 模塊運行時,進行 HTTP Digest 認證的過程中,此變數被設置成客戶端發送的「Authorization」HTTP 頭內容(以便作進一步的認證操作)。

30、$_SERVER['PHP_AUTH_USER']-- 當 PHP 運行在 Apache 或 IIS(PHP 5 是 ISAPI)模塊方式下,並且正在使用 HTTP 認證功能,這個變數便是用戶輸入的用戶名。

31、$_SERVER['PHP_AUTH_PW'] -- 當 PHP 運行在 Apache 或 IIS(PHP 5 是 ISAPI)模塊方式下,並且正在使用 HTTP 認證功能,這個變數便是用戶輸入的密碼。

32、$_SERVER['AUTH_TYPE']--當 PHP 運行在 Apache 模塊方式下,並且正在使用 HTTP 認證功能,這個變數便是認證的類型。

5. 使用thinkphp 怎麼實現反向代理

改自PHP Reverse Proxy PRP,修改了原版中的一些錯誤,支持了文件上傳以及上傳文件類型識別,支持指定IP,自適應SAE環境。
使用方法
?123456789 <?php $proxy=new PhpReverseProxy(); $proxy->port="8080"; $proxy->host="ww"; //$proxy->ip="1.1.1.1"; $proxy->forward_path=""; $proxy->connect(); $proxy->output(); ?>
源代碼
<?php //Source Code: http //www xiumu.org/technology/php-reverse-proxy-class.shtml class PhpReverseProxy{ public $publicBaseURL; public $outsideHeaders; public $XRequestedWith; public $sendPost; public $port,$host,$ip,$content,$forward_path,$content_type,$user_agent, $XFF,$request_method,$IMS,$cacheTime,$cookie,$authorization; private $http_code,$lastModified,$version,$resultHeader; const chunkSize = 10000; function __construct(){ $this->version="PHP Reverse Proxy (PRP) 1.0"; $this->port="8080"; $this->host="127.0.0.1"; $this->ip=""; $this->content=""; $this->forward_path=""; $this->path=""; $this->content_type=""; $this->user_agent=""; $this->http_code=""; $this->XFF=""; $this->request_method="GET"; $this->IMS=false; $this->cacheTime=72000; $this->lastModified=gmdate("D, d M Y H:i:s",time()-72000)." GMT"; $this->cookie=""; $this->XRequestedWith = ""; $this->authorization = ""; } function translateURL($serverName) { $this->path=$this->forward_path.$_SERVER['REQUEST_URI']; if(IS_SAE) return $this->translateServer($serverName).$this->path; if($_SERVER['QUERY_STRING']=="") return $this->translateServer($serverName).$this->path; else return $this->translateServer($serverName).$this->path."?".$_SERVER['QUERY_STRING']; } function translateServer($serverName) { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = $this->left(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; if($this->port=="") return $protocol."://".$serverName; else return $protocol."://".$serverName.":".$this->port; } function left($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } function preConnect(){ $this->user_agent=$_SERVER['HTTP_USER_AGENT']; $this->request_method=$_SERVER['REQUEST_METHOD']; $tempCookie=""; foreach ($_COOKIE as $i => $value) { $tempCookie=$tempCookie." $i=$_COOKIE[$i];"; } $this->cookie=$tempCookie; if(empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $this->XFF=$_SERVER['REMOTE_ADDR']; } else { $this->XFF=$_SERVER['HTTP_X_FORWARDED_FOR'].", ".$_SERVER['REMOTE_ADDR']; } } function connect(){ if(empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ $this->preConnect(); $ch=curl_init(); if($this->request_method=="POST"){ curl_setopt($ch, CURLOPT_POST,1); $postData = array(); $filePost = false; $uploadPath = 'uploads/'; if (IS_SAE) $uploadPath = SAE_TMP_PATH; if(count($_FILES)>0){ if(!is_writable($uploadPath)){ die('You cannot upload to the specified directory, please CHMOD it to 777.'); } foreach($_FILES as $key => $fileArray){ ($fileArray["tmp_name"], $uploadPath . $fileArray["name"]); $proxyLocation = "@" . $uploadPath . $fileArray["name"] . ";type=" . $fileArray["type"]; $postData = array($key => $proxyLocation); $filePost = true; } } foreach($_POST as $key => $value){ if(!is_array($value)){ $postData[$key] = $value; } else{ $postData[$key] = serialize($value); } } if(!$filePost){ //$postData = http_build_query($postData); $postString = ""; $firstLoop = true; foreach($postData as $key => $value){ $parameterItem = urlencode($key)."=".urlencode($value); if($firstLoop){ $postString .= $parameterItem; } else{ $postString .= "&".$parameterItem; } $firstLoop = false; } $postData = $postString; } //echo print_r($postData); //curl_setopt($ch, CURLOPT_VERBOSE, 0); //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); $this->sendPost = $postData; //var_mp(file_exists(str_replace('@','',$postData['imgfile'])));exit; curl_setopt($ch, CURLOPT_POSTFIELDS,$postData); //curl_setopt($ch, CURLOPT_POSTFIELDS,file_get_contents($proxyLocation)); //curl_setopt($ch, CURLOPT_POSTFIELDS,file_get_contents("php://input")); } //gets rid of mulitple ? in URL $translateURL = $this->translateURL(($this->ip)?$this->ip:$this->host); if(substr_count($translateURL, "?")>1){ $firstPos = strpos($translateURL, "?", 0); $secondPos = strpos($translateURL, "?", $firstPos + 1); $translateURL = substr($translateURL, 0, $secondPos); } curl_setopt($ch,CURLOPT_URL,$translateURL); $proxyHeaders = array( "X-Forwarded-For: ".$this->XFF, "User-Agent: ".$this->user_agent, "Host: ".$this->host ); if(strlen($this->XRequestedWith)>1){ $proxyHeaders[] = "X-Requested-With: ".$this->XRequestedWith; //echo print_r($proxyHeaders); } curl_setopt($ch,CURLOPT_HTTPHEADER, $proxyHeaders); if($this->cookie!=""){ curl_setopt($ch,CURLOPT_COOKIE,$this->cookie); } curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false); curl_setopt($ch,CURLOPT_AUTOREFERER,true); curl_setopt($ch,CURLOPT_HEADER,true); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output=curl_exec($ch); $info = curl_getinfo( $ch ); curl_close($ch); $this->postConnect($info,$output); }else { $this->lastModified=$_SERVER['HTTP_IF_MODIFIED_SINCE']; $this->IMS=true; } } function postConnect($info,$output){ $this->content_type=$info["content_type"]; $this->http_code=$info['http_code']; //var_mp($info);exit; if(!empty($info['last_modified'])){ $this->lastModified=$info['last_modified']; } $this->resultHeader=substr($output,0,$info['header_size']); $content = substr($output,$info['header_size']); if($this->http_code=='200'){ $this->content=$content; }elseif( ($this->http_code=='302' || $this->http_code=='301') && isset($info['redirect_url'])){ $redirect_url = str_replace($this->host,$_SERVER['HTTP_HOST'],$info['redirect_url']); if (IS_SAE) $redirect_url = str_replace('http://fetchurl.sae.sina.com.cn/','',$info['redirect_url']); header("Location: $redirect_url"); exit; }elseif($this->http_code=='404'){ header("HTTP/1.1 404 Not Found"); exit("HTTP/1.1 404 Not Found"); }elseif($this->http_code=='500'){ header('HTTP/1.1 500 Internal Server Error'); exit("HTTP/1.1 500 Internal Server Error"); }else{ exit("HTTP/1.1 ".$this->http_code." Internal Server Error"); } } function output(){ $currentTimeString=gmdate("D, d M Y H:i:s",time()); $expiredTime=gmdate("D, d M Y H:i:s",(time()+$this->cacheTime)); $doOriginalHeaders = true; if($doOriginalHeaders){ if($this->IMS){ header("HTTP/1.1 304 Not Modified"); header("Date: Wed, $currentTimeString GMT"); header("Last-Modified: $this->lastModified"); header("Server: $this->version"); }else{ header("HTTP/1.1 200 OK"); header("Date: Wed, $currentTimeString GMT"); header("Content-Type: ".$this->content_type); header("Last-Modified: $this->lastModified"); header("Cache-Control: max-age=$this->cacheTime"); header("Expires: $expiredTime GMT"); header("Server: $this->version"); preg_match("/Set-Cookie:[^\n]*/i",$this->resultHeader,$result); foreach($result as $i=>$value){ header($result[$i]); } preg_match("/Content-Encoding:[^\n]*/i",$this->resultHeader,$result); foreach($result as $i=>$value){ //header($result[$i]); } preg_match("/Transfer-Encoding:[^\n]*/i",$this->resultHeader,$result); foreach($result as $i=>$value){ //header($result[$i]); } echo($this->content); /* if(stristr($this->content, "error")){ echo print_r($this->sendPost); } */ } } else{ $headerString = $this->resultHeader; //string $headerArray = explode("\n", $headerString); foreach($headerArray as $privHeader){ header($privHeader); } if(stristr($headerString, "Transfer-encoding: chunked")){ flush(); ob_flush(); $i = 0; $maxLen = strlen($this->content); while($i < $maxLen){ $endChar = $i + self::chunkSize; if($endChar >= $maxLen){ $endChar = $maxLen - 1; } $chunk = substr($this->content, $i, $endChar); $this->mp_chunk($chunk); flush(); ob_flush(); $i = $i + $endChar; } } else{ echo($this->content); } //echo "header: ".print_r($headerArray); //header($this->resultHeader); } } function mp_chunk($chunk) { echo sprintf("%x\r\n", strlen($chunk)); echo $chunk; echo "\r\n"; } function getOutsideHeaders(){ $headers = array(); foreach ($_SERVER as $name => $value){ if (substr($name, 0, 5) == 'HTTP_') { $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); $headers[$name] = $value; }elseif ($name == "CONTENT_TYPE") { $headers["Content-Type"] = $value; }elseif ($name == "CONTENT_LENGTH") { $headers["Content-Length"] = $value; }elseif(stristr($name, "X-Requested-With")) { $headers["X-Requested-With"] = $value; $this->XRequestedWith = $value; } } //echo print_r($headers); $this->outsideHeaders = $headers; return $headers; } } ?>

6. PHP curl 模擬 請求 中我添加 Authorization 認證 但是這個認證內容我接受不到 沒有開安全模式 何解

代碼如下
$crl = curl_init();
$headr = array();
$headr[] = 'Authorization: '.$douban_user_name.' '.$accesstoken;
curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($crl, CURLOPT_POST,true);
$rest = curl_exec($crl);
curl_close($crl);
print_r($rest);

7. php中http請求頭有什麼內容,由什麼組成

PHP中一般採用getallheaders來獲取頭部,但事實上,有些模式下是獲取不到的(以前真沒有注意過在fastcgi下這個函數不能用)
在PHP里,想要得到所有的HTTP請求頭,可以使用getallheaders方法,不過此方法並不是在任何環境下都存在,比如說,你使用fastcgi方式運行PHP的話,就沒有這個方法,所以說我們還需要考慮別的方法,幸運的是$_SERVER里有我們想要的東西,它裡面鍵名以HTTP_開頭的就是HTTP請求頭:
$headers = array();
foreach ($_SERVER as $key => $value) {
if ('HTTP_' == substr($key, 0, 5)) {
$headers[str_replace('_', '-', substr($key, 5))] = $value;
}
}
代碼很簡單,需要說明的是RFC里明確指出了信息頭的名字是不區分大小寫的。
不過並不是所有的HTTP請求頭都是以HTTP_開頭的的鍵的形式存在與$_SERVER里,比如說Authorization,Content-Length,Content-Type就不是這樣,所以說為了取得所有的HTTP請求頭,還需要加上下面這段代碼:
if (isset($_SERVER['PHP_AUTH_DIGEST'])) {
$header['AUTHORIZATION'] = $_SERVER['PHP_AUTH_DIGEST']);
} elseif (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$header['AUTHORIZATION'] = base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']));
}
if (isset($_SERVER['CONTENT_LENGTH'])) {
$header['CONTENT-LENGTH'] = $_SERVER['CONTENT_LENGTH'];
}
if (isset($_SERVER['CONTENT_TYPE'])) {
$header['CONTENT-TYPE'] = $_SERVER['CONTENT_TYPE'];
}

8. 打開php.ini中的Safe_mode,會影響哪些參數至少說出6個。

system,passthru,exec,shell_exec,popen,phpinfo等等大部分的文件操作函數。
因為Safe_mode是php非常重要的內嵌的安全機制。默認是關閉的。

9. php手機端怎麼獲取微信openid

//***方法一
獲取code
https://open.weixin.qq.com/connect/oauth2/authorize?appid=這里是你的公眾號的APPID&redirect_uri=http://www.xx.com/getcode&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect
用戶點擊確認登錄,自動跳轉下面地址得到code
http://www.xx.com/getcode 這個是你自己的跳轉地址
http://www.xx.com/getcode?code=&state=123
後面的這個 ?code=……123 是微信自動跳轉添加的,不是你自己加的
下面是PHP語言,寫在getcode這個頁面里
$code = $_GET['code'];//獲取code
$weixin = file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=這里是你的APPID&secret=這里是你的SECRET&code=".$code."&grant_type=authorization_code");//通過code換取網頁授權access_token
$jsondecode = json_decode($weixin); //對JSON格式的字元串進行編碼
$array = get_object_vars($jsondecode);//轉換成數組
$openid = $array['openid'];//輸出openid
//***方法二
$appid = "公眾號在微信的appid";
$secret = "公眾號在微信的app secret";
$code = $_GET["code"];
$get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$get_token_url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
curl_close($ch);
$json_obj = json_decode($res,true);
//根據openid和access_token查詢用戶信息
$access_token = $json_obj['access_token'];
$openid = $json_obj['openid'];
$get_user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$get_user_info_url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
curl_close($ch);
//解析json
$user_obj = json_decode($res,true);
$_SESSION['user'] = $user_obj;
print_r($user_obj);

10. php header頭如何添加Authorization登錄驗證

session有作用域,建議把session存到全局空間中去,每次登陸時候取全局裡面的數據驗證

熱點內容
如何查看java版本 發布:2024-05-05 16:45:05 瀏覽:494
轉子繞組電動機控制櫃如何配置 發布:2024-05-05 16:45:04 瀏覽:916
搭建游戲要多大伺服器 發布:2024-05-05 16:44:16 瀏覽:345
雲伺服器ecs網站 發布:2024-05-05 16:35:55 瀏覽:562
c語言列印正方形 發布:2024-05-05 16:09:20 瀏覽:643
編程用箭頭 發布:2024-05-05 15:54:21 瀏覽:794
步驟條源碼 發布:2024-05-05 15:35:55 瀏覽:846
安卓拍光遇視頻如何高清 發布:2024-05-05 15:23:20 瀏覽:934
linuxo文件 發布:2024-05-05 15:19:12 瀏覽:945
手機伺服器地址或者域名 發布:2024-05-05 15:19:09 瀏覽:374