Home > php教程 > php手册 > PHP隐藏URL参数名的方法

PHP隐藏URL参数名的方法

WBOY
Release: 2016-06-06 19:56:52
Original
1890 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 用PHP伪静态隐藏URL传递参数名的四种方法: PHP中的伪静态主要是为了隐藏传递的参数名,看在url上看不到传递的参数是什么,下面介绍四种方法。 方法一: ?php // localhost/php100/test.php/1/2 $fil

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  用PHP伪静态隐藏URL传递参数名的四种方法:

  PHP中的伪静态主要是为了隐藏传递的参数名,看在url上看不到传递的参数是什么,下面介绍四种方法。

  方法一:

  

  // localhost/php100/test.php/1/2

  $filename = basename($_SERVER['SCRIPT_NAME']);

  echo $_SERVER['SCRIPT_NAME']."
";// /php100/test.php

  echo $filename."
";// test.php

  if(strtolower($filename)=='test.php'){

  if(!empty($_GET[id])){

  $id=intval($_GET[id]);

  echo $id."
";

  $action=intval($_GET[action]);

  echo $action."
";

  }else{

  $nav=$_SERVER['REQUEST_URI'];

  echo "1:".$nav."
";// /php100/test.php/1/2

  $script=$_SERVER['SCRIPT_NAME'];

  echo "2:".$script."
";// /php100/test.php

  $nav=ereg_replace("^$script","",urldecode($nav));

  echo $nav."
"; // /1/2

  $vars=explode("/",$nav);

  print_r($vars);// Array ( [0] => [1] => 1 [2] => 2 )

  echo "
";

  $id=intval($vars[1]);

  $action=intval($vars[2]);

  }

  echo $id.'&'.$action;

  }

  ?>

  方法二:

  

  // localhost/php100/test.php?id|1@action|2

  $Php2Html_FileUrl = $_SERVER["REQUEST_URI"];

  echo $Php2Html_FileUrl."
";

  // /php100/test.php?id|1@action|2

  $Php2Html_UrlString = str_replace("?","",str_replace("/", "", strrchr(strrchr($Php2Html_FileUrl, "/"),"?")));

  echo $Php2Html_UrlString."
";

  // id|1@action|2

  $Php2Html_UrlQueryStrList = explode("@", $Php2Html_UrlString);

  print_r($Php2Html_UrlQueryStrList);

  // Array ( [0] => id|1 [1] => action|2 ) echo "
";

  foreach($Php2Html_UrlQueryStrList as $Php2Html_UrlQueryStr) {

  $Php2Html_TmpArray = explode("|", $Php2Html_UrlQueryStr);

  print_r($Php2Html_TmpArray);

  // Array ( [0] => id [1] => 1 ) ; Array ( [0] => action [1] => 2 )

  echo "
";

  $_GET[$Php2Html_TmpArray[0]] = $Php2Html_TmpArray[1];

  }

  //echo '假静态:$_GET变量
';

  print_r($_GET);

  // Array ( [id|1@action|2] => [id] => 1 [action] => 2 ) echo "
";

  echo "


";

  echo $_GET[id]."
";

  // 1 echo $_GET[action];

  // 2

  ?>

[1] [2] 

PHP隐藏URL参数名的方法

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template