php method to get the url before jumping: 1. JAVASCRIPT client method to get the URL with QUESTRING parameter; 2. Regular analysis method, set or get the entire URL as a string, the code is [alert(window. location.href)].
php method to get the url before jump:
1: Get the JAVASCRIPT client of the URL with QUESTRING parameter Solution, equivalent to asp's request.querystring, PHP's $_GET
1. Function:
<Script language="javascript"> function GetRequest() { var url = location.search; //获取duurl中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") !zhi= -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]); } } return theRequest; } </Script>
2. Then get the corresponding parameter value by calling this function:
<Script language="javascript"> var Request = new Object(); Request = GetRequest(); var 参数1,参数2,参数3,参数N; 参数1 = Request[''参数1'']; 参数2 = Request[''参数2'']; 参数3 = Request[''参数3'']; 参数N = Request[''参数N'']; </Script>
Use this to obtain the parameter with the same name in the url string
2. Regular analysis method.
function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i"); var r = window.location.search.substr(1).match(reg); if (r!=null) return (r[2]); return null; } alert(GetQueryString("参数名1")); alert(GetQueryString("参数名2")); alert(GetQueryString("参数名3"));
Other parameter acquisition introduction:
//Set or get the file name or path specified by the object.
alert(window.location.pathname);
//Set or get the entire URL as a string.
alert(window.location.href);
//Set or get the port number associated with the URL.
alert(window.location.port);
//Set or get the protocol part of the URL.
alert(window.location.protocol);
//Set or get the segment after the pound sign "#" in the href attribute.
alert(window.location.hash);
//Set or get the hostname and port number of location or URL.
alert(window.location.host);
//Set or get the part following the question mark in the href attribute.
alert(window.location.search);
Related learning recommendations: php programming (video)
The above is the detailed content of How to get the url before jump in php. For more information, please follow other related articles on the PHP Chinese website!