Home Backend Development PHP Problem How to get the url before jump in php

How to get the url before jump in php

Aug 11, 2020 am 10:34 AM
php

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)].

How to get the url before jump in php

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>
Copy after login

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>
Copy after login

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"));
Copy after login

Other parameter acquisition introduction:

//Set or get the file name or path specified by the object.

alert(window.location.pathname);
Copy after login

//Set or get the entire URL as a string.

alert(window.location.href);
Copy after login

//Set or get the port number associated with the URL.

alert(window.location.port);
Copy after login

//Set or get the protocol part of the URL.

alert(window.location.protocol);
Copy after login

//Set or get the segment after the pound sign "#" in the href attribute.

alert(window.location.hash);
Copy after login

//Set or get the hostname and port number of location or URL.

alert(window.location.host);
Copy after login

//Set or get the part following the question mark in the href attribute.

alert(window.location.search);
Copy after login

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

See all articles