search
HomeBackend DevelopmentPHP TutorialPHP method to obtain the real address and response header information after the short link jumps, the jump is true_PHP tutorial

To obtain a short link, you need to convert the short link into a real URL. After checking the information, I found that PHP provides a function get_headers(), which can complete this task. First, get the header information, and then analyze the jump. Just transfer the address:

Copy code The code is as follows:

$url = 'http://t.cn/h5mwx';
$headers = get_headers($url, TRUE);

print_r($headers);

//Output the URL to jump to
echo $headers['Location'];

Attached is the complete array:

Copy code The code is as follows:

Array
(
[0] => HTTP/1.1 302 Moved Temporarily
[Location] => http://www.baidu.com
[Content-Type] => Array
(
                                                                                                                                                                                                                                    [1] => text/html;charset=utf-8
)
[Server] => Array

(
                                                                      [0] => weibo
                                                                  [1] => BWS/1.0
)

[Content-Length] => Array

(
                                                                                            [0] => 203
                                                                                        [1] => 16424
)

[Date] => Array

(
​​​​​​[0] => ​​​​​​[1] => Thu, 12 Dec 2013 10:42:25 GMT
)

[X-Varnish] => 2893360335

[Age] => 0

[Via] => 1.1 varnish
[Connection] => Array
(
                                                    [0] => close
                                                                                                                    [1] => Close
)
)


Attachment: official documentation of get_headers function

get_headers

— Get all headers sent by the server in response to an HTTP request

Description

array get_headers ( string $url [, int $format = 0 ] )

get_headers() returns an array containing the headers sent by the server in response to an HTTP request.

Parameters

url: Target URL.

format: If the optional format parameter is set to 1, get_headers() will parse the corresponding information and set the key name of the array.

Return value

Returns an index or associative array containing the headers sent by the server in response to an HTTP request, or FALSE on failure.

Usage example:


Copy code The code is as follows:
$url = 'http://www.example.com';

print_r(get_headers($url));

print_r(get_headers($url, 1));

?>


The output of the above routine is similar to:

Copy code The code is as follows:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Date: Sat, 29 May 2004 12:28:13 GMT
    [2] => Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
    [4] => ETag: "3f80f-1b6-3e1cb03b"
    [5] => Accept-Ranges: bytes
    [6] => Content-Length: 438
    [7] => Connection: close
    [8] => Content-Type: text/html
)

Array
(
    [0] => HTTP/1.1 200 OK
    [Date] => Sat, 29 May 2004 12:28:14 GMT
    [Server] => Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
    [ETag] => "3f80f-1b6-3e1cb03b"
    [Accept-Ranges] => bytes
    [Content-Length] => 438
    [Connection] => close
    [Content-Type] => text/html
)

php 怎获取 JS跳转的链接

test1.php
$a="text2.php";
echo "";

test.php
include_once "test1.php";
echo $a;

就是这个意思,具体没有测试。test.php通过包含test1.php页面,输出test1.php页面中的变量"test2.php"。
 

怎获取跳转后的链接(php可以解决不)

用$_SERVER['HTTP_REFERER'];和session结合使用,或者把访问的链接都放在一个数组里
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/848803.htmlTechArticlePHP获取短链接跳转后的真实地址和响应头信息的方法,跳转的真 获取到一个短连接,需要将短连接转换成真实的网址,通过查资料,发现...
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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor