導航:首頁 > 編程語言 > phpurlhash

phpurlhash

發布時間:2022-08-18 00:59:12

① 關於php網站URL地址「加密」或轉義的問題

PHP 函數 strtr

$trans = array('1'=>'a', '2'=>'b', '3'=>'c', '4'=>'d', '5'=>'e', '6'=>'f', '7'=>'g', '8'=>'h', '9'=>'i', '0'=>'z');
$url = 'aa.com/ct-9326664726.html';
echo strtr($url, $trans);
// 輸出 aa.com/ct-icbfffdgbf.html

② 使用 URL 的 hash 來模擬一個完整的 URL,於是當 URL 改變時,頁面不會重新載入,就是hash路由模式嗎

是的,這種工作方式最大的好處不會改變URL,同時也能產生歷史記錄,方便追溯歷史。
hash 模式,利用是網頁錨點完成,該模式工作是需要依託於網頁中的內容被載入。
在靜態頁面中使用,由於靜態頁面已經被緩存,可以減少伺服器壓力,同時又能起到很好的頁面導航效果。
優點:適用於靜態頁面,快速輸出文本內容,具有頁面位置導航效果
缺點:不宜頁面文件過大,否則需要搭配 ajax 方法來獲取網頁內容,以減少伺服器壓力

③ 如何在PHP中實現URL路由

第一步,首先要在伺服器的配置上對/router/路徑進行攔截

調用某個文件夾目錄下的index.php頁面,假定現在所有模塊使用單獨的文件存放於class目錄下,該目錄與router平級,如下圖所示:

第二步,路由分發器的實現(index.php)
1: <!Doctype html>
2: <html>
3: <head>
4: <title>路由測試~~</title>
5: <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6: </head>
7: <body>
8:
9: <?php
10:
11: date_default_timezone_set("Asia/Shanghai");
12:
13: define("MODULE_DIR", "../class/");
14:
15:
16: $_DocumentPath = $_SERVER['DOCUMENT_ROOT'];
17: $_FilePath = __FILE__;
18: $_RequestUri = $_SERVER['REQUEST_URI'];
19:
20: $_AppPath = str_replace($_DocumentPath, '', $_FilePath); //==>\router\index.php
21: $_UrlPath = $_RequestUri; //==>/router/hello/router/a/b/c/d/abc/index.html?id=3&url=http:
22:
23: $_AppPathArr = explode(DIRECTORY_SEPARATOR, $_AppPath);
24:
25: /**
26: * http://192.168.0.33/router/hello/router/a/b/c/d/abc/index.html?id=3&url=http:
27: *
28: * /hello/router/a/b/c/d/abc/index.html?id=3&url=http:
29: */
30:
31: for ($i = 0; $i < count($_AppPathArr); $i++) {
32: $p = $_AppPathArr[$i];
33: if ($p) {
34: $_UrlPath = preg_replace('/^\/'.$p.'\//', '/', $_UrlPath, 1);
35: }
36: }
37:
38: $_UrlPath = preg_replace('/^\//', '', $_UrlPath, 1);
39:
40: $_AppPathArr = explode("/", $_UrlPath);
41: $_AppPathArr_Count = count($_AppPathArr);
42:
43: $arr_url = array(
44: 'controller' => 'index',
45: 'method' => 'index',
46: 'parms' => array()
47: );
48:
49: $arr_url['controller'] = $_AppPathArr[0];
50: $arr_url['method'] = $_AppPathArr[1];
51:
52: if ($_AppPathArr_Count > 2 and $_AppPathArr_Count % 2 != 0) {
53: die('參數錯誤');
54: } else {
55: for ($i = 2; $i < $_AppPathArr_Count; $i += 2) {
56: $arr_temp_hash = array(strtolower($_AppPathArr[$i])=>$_AppPathArr[$i + 1]);
57: $arr_url['parms'] = array_merge($arr_url['parms'], $arr_temp_hash);
58: }
59: }
60:
61: $mole_name = $arr_url['controller'];
62: $mole_file = MODULE_DIR.$mole_name.'.class.php';
63: $method_name = $arr_url['method'];
64:
65: if (file_exists($mole_file)) {
66: include $mole_file;
67:
68: $obj_mole = new $mole_name();
69:
70: if (!method_exists($obj_mole, $method_name)) {
71: die("要調用的方法不存在");
72: } else {
73: if (is_callable(array($obj_mole, $method_name))) {
74: $obj_mole -> $method_name($mole_name, $arr_url['parms']);
75:
76: $obj_mole -> printResult();
77: }
78: }
79:
80: } else {
81: die("定義的模塊不存在");
82: }
83:
84:
85: ?>
86:
87: </body>
88: </html>

獲取請求的uri,然後拿到要載入的模塊名、調用方法名,對uri參數進行簡單的判斷..

第三步,模塊的編寫
根據上述的uri,我們要調用的是Hello模塊下的router方法,那麼可以在class目錄下定義一個名為Hello.class.php的文件(注意linux下是區分大小寫的)
1: <?php
2:
3: class Hello {
4:
5: private $_name;
6: private $_varValue;
7:
8: function __construct() {
9:
10: }
11:
12: function router() {
13: $this->_name = func_get_arg(0);
14: $this->_varValue = func_get_arg(1);
15: }
16:
17: function printResult() {
18: echo $this->_name;
19: echo "<p>";
20: echo var_mp($this->_varValue);
21: echo "</p>";
22: }
23: }
24:
25: ?>

④ php的公共類是如何做到url變更而頁面不刷新的

咨詢記錄 · 回答於2021-05-20

⑤ php代碼hash解析

就是生成一段hash值,比md5和sha1更加安全而已

⑥ 生成短鏈接,php5.6可用,為什麼php7生成不了

#短連接生成演算法

class Short_Url {
#字元表
public static $charset = "";

public static function short($url) {
$key = "alexis";
$urlhash = md5($key . $url);
$len = strlen($urlhash);

#將加密後的串分成4段,每段4位元組,對每段進行計算,一共可以生成四組短連接
for ($i = 0; $i < 4; $i++) {
$urlhash_piece = substr($urlhash, $i * $len / 4, $len / 4);
#將分段的位與0x3fffffff做位與,0x3fffffff表示二進制數的30個1,即30位以後的加密串都歸零
$hex = hexdec($urlhash_piece) & 0x3fffffff; #此處需要用到hexdec()將16進制字元串轉為10進制數值型,否則運算會不正常

$short_url = "http://t.cn/";
#生成6位短連接
for ($j = 0; $j < 6; $j++) {
#將得到的值與0x0000003d,3d為61,即charset的坐標最大值
$short_url .= self::$charset[$hex & 0x0000003d];
#循環完以後將hex右移5位
$hex = $hex >> 5;
}

$short_url_list[] = $short_url;
}

return $short_url_list;
}
}

$url = "http://www.cnblogs.com/zemliu/";
$short = Short_Url::short($url);
print_r($short);
********************************
調用方法:
$short = Short_Url::short('www..com');
var_mp($short);
//省略鏈接memcache
$memcache->set($cacheKey.$short[0],「原始地址」);
************************************

好了,短網址還原了實際就是這個樣子的了,可能你看到新浪微博應用裡面的短網址都是這個樣子:
http://t.cn/zHEYrvV
其實他還原了說不定就是這個樣子:
http://t.cn/link.php?url=http://www.Alixixi.com/php-template-framework/832.html
好了,這里就說到第二步了,如何將
http://t.cn/link.php?url=http://www.Alixixi.com/php-template-framework/832.html
縮成
http://t.cn/zHEYrvV
這個地方需要用到url重寫,按照本例則可以這么重寫:
RewriteEngine On
RewriteBase /
RewriteRule ^/(.*)$ link.php?url=$1[L]

⑦ php url參數加密

加密:$str = base64_encode("123");
解密:base64_decode($str);

⑧ php 判斷是post還是get

PHP 判斷是否為Get/Post/Ajax提交

/**
* 是否是AJAx提交的
* @return bool
*/
function isAjax(){
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
return true;
}else{
return false;
}
}

/**
* 是否是GET提交的
*/
function isGet(){
return $_SERVER['REQUEST_METHOD'] == 'GET' ? true : false;
}

/**
* 是否是POST提交
* @return int
*/
function isPost() {
return ($_SERVER['REQUEST_METHOD'] == 'POST' && checkurlHash($GLOBALS['verify']) && (empty($_SERVER['HTTP_REFERER']) || preg_replace("~https?:\/\/([^\:\/]+).*~i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("~([^\:]+).*~", "\\1", $_SERVER['HTTP_HOST']))) ? 1 : 0;
}

⑨ php的URL傳參,通過URL傳!

PHPURL傳參是向URL裡面添加字元串的方式來進行傳遞的。
例:
index.php?id=100&name=test
上面這個url傳遞了id為100,name為test的傳,可以通過$_GET['id']和$_GET['name']分別獲取這兩個值。

⑩ php打開URL的幾種方法

PHP中打開URL地址的幾種方法總結,這里的函數主要用於小偷採集等函數。
1:用file_get_contents
以get方式獲取內容
復制代碼代碼如下:

<?php
$url='http://www..com/';

$html=file_get_contents($url);
//print_r($http_response_header);

ec($html);
printhr();
printarr($http_response_header);

printhr();
?>

示例代碼2:用fopen打開url,
以get方式獲取內容
復制代碼代碼如下:

<?
$fp=fopen($url,'r');

printarr(stream_get_meta_data($fp));
printhr();
while(!feof($fp)){

$result.=fgets($fp,1024);
}
echo"urlbody:$result";

printhr();
fclose($fp);
?>


示例代碼3:用file_get_contents函數,以post方式獲取url
復制代碼代碼如下:

<?php
$data=array('foo'=>
'bar');
$data=http_build_query($data);
$opts=array(
'http'
=>array(
'method'=>'POST',
'header'=>"Content-type:
application/x-www-form-urlencoded".
"Content-Length:".strlen($data).
"",
'content'=>$data
),
);
$context=
stream_context_create($opts);
$html=
file_get_contents('http://localhost/e/admin/test.html',false,$context);

echo$html;
?>


示例代碼4:用fsockopen函數打開url,以get方式獲取完整的數據,包括header和body
復制代碼代碼如下:

<?
functionget_url
($url,$cookie=false){
$url=parse_url($url);
$query=
$url[path]."?".$url[query];
ec("Query:".$query);
$fp=fsockopen(
$url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
if(!$fp){

returnfalse;
}else{
$request="GET$queryHTTP/1.1";

$request.="Host:$url[host]";
$request.="Connection:Close";

if($cookie)$request.="Cookie:$cookie ";
$request.="";

fwrite($fp,$request);
while(!@feof($fp)){
$result.=@fgets($fp,
1024);
}
fclose($fp);
return$result;
}
}

//獲取url的html部分,去掉header
functionGetUrlHTML($url,$cookie=false){

$rowdata=get_url($url,$cookie);
if($rowdata)
{
$body=
stristr($rowdata,"");
$body=substr($body,4,strlen($body));
return$body;

}
returnfalse;
}

?>

閱讀全文

與phpurlhash相關的資料

熱點內容
pythonclass使用方法 瀏覽:221
移動加密軟體去哪下載 瀏覽:281
php彈出alert 瀏覽:207
吉林文檔課件加密費用 瀏覽:131
感測器pdf下載 瀏覽:284
隨車拍app綁定什麼設備 瀏覽:896
方維團購系統源碼 瀏覽:991
linux反彈shell 瀏覽:159
列印機介面加密狗還能用嗎 瀏覽:300
二板股票源碼 瀏覽:448
度人經pdf 瀏覽:902
怎麼配置android遠程伺服器地址 瀏覽:960
java程序員看哪些書 瀏覽:943
什麼app可以免費和外國人聊天 瀏覽:797
pdf手寫筆 瀏覽:182
別永遠傷在童年pdf 瀏覽:990
愛上北斗星男友在哪個app上看 瀏覽:421
主力散戶派發源碼 瀏覽:671
linux如何修復伺服器時間 瀏覽:61
榮縣優途網約車app叫什麼 瀏覽:479