Home  >  Article  >  Backend Development  >  How to use preg_match to intercept the URL and fail to pass parameters?

How to use preg_match to intercept the URL and fail to pass parameters?

PHP中文网
PHP中文网Original
2016-06-27 13:18:071033browse

I want to call the data of another website on one website, so that both websites can call the same data, just like

is called locally.

For example: my website a and website b

If I enter: http://www.a.com/x.php/123/456.rar
actually call The one is: http://www.b.com/123/456.rar (the real file storage address)
When downloading, it still shows that it is downloaded from www.a.com.

My x.php is like this:

<?php  
 header("content-Type: text/html; charset=Utf-8");  
 $SERVER=$_SERVER["REQUEST_URI"];  
 preg_match("/php\/([\s\S]+)\.rar/",$SERVER,$url);  
 $urlname=$url[1];  
 $songurl=&#39;http://www.b.com/&#39;.$urlname.&#39;/&#39;;  
 header("location:$songurl");  
 ?>


It is through this code that 123 in the first URL is passed to the second URL.
But the code above did not pass successfully:
I entered http://www.a.com/x.php/123/456.rar, and the second URL displayed was:

http://www.b.com. "123" is not displayed in the URL. Please tell me what modifications I need to make so that the second URL can get the passed parameters "123" and "456".

Solution

1. First confirm whether the content in
$_SERVER["REQUEST_URI"] is x.php/ 123/456.rar
2. The regular expression is actually changed to
preg_match("/php/([sS] .rar)/",$SERVER,$url);
$urlname=$url[1 ];
$songurl='http://www.b.com/'.$urlname; // In this way, it can be pieced together into a http://www.b.com/123/456.rar suffix ending with rar Links

Statement:
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