导航:首页 > 编程语言 > 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相关的资料

热点内容
随车拍app绑定什么设备 浏览:893
方维团购系统源码 浏览:988
linux反弹shell 浏览:152
打印机接口加密狗还能用吗 浏览:299
二板股票源码 浏览:446
度人经pdf 浏览:902
怎么配置android远程服务器地址 浏览:960
java程序员看哪些书 浏览:943
什么app可以免费和外国人聊天 浏览:796
pdf手写笔 浏览:182
别永远伤在童年pdf 浏览:990
爱上北斗星男友在哪个app上看 浏览:421
主力散户派发源码 浏览:671
linux如何修复服务器时间 浏览:61
荣县优途网约车app叫什么 浏览:479
百姓网app截图是什么意思 浏览:229
php如何嵌入html 浏览:817
解压专家怎么传输 浏览:745
如何共享服务器的网络连接 浏览:136
程序员简易表白代码 浏览:170