现在有很多的短网址应用,点击就跳转到缩短之前的网址了,那今天我们就来看一下,PHP如何获取短网址跳转之前的网址,其实也很简单,就是用php的get_headers 函数,取得Response Headers,之后慢慢分析就行了。
给出具体实现方法,代码如下:
- $header = get_headers($url, 1);
- if (strpos($header[0], ’301′) || strpos($header[0], ’302′)) {
- if (is_array($header['Location'])) {
- return $header['Location'][count($header['Location'])-1];
- } else {
- return $header['Location'];
- }
- } else {
- return $url;
- }
实例二,代码如下:
- <!–?php
- //
- echo get_redirect_url('http://www.phpfensi.com');
- //输出结果为:http://code.google.com/android/
- function get_redirect_url($url){
- $redirect_url = null;
- $url_parts = @parse_url($url);
- if (!$url_parts) return false;
- if (!isset($url_parts['host'])) return false; //can't process relative URLs
- if (!isset($url_parts['path'])) $url_parts['path'] = '/';
- $sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
- if (!$sock) return false;
- $request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1rn";
- $request .= 'Host: ' . $url_parts['host'] . "rn";
- $request .= "Connection: Closernrn";
- fwrite($sock, $request);
- $response = '';
- while(!feof($sock)) $response .= fread($sock, 8192);
- fclose($sock);
- if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
- if ( substr($matches[1], 0, 1) == "/" )
- return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);
- else
- return trim($matches[1]);
- } else {
- return false;
- }
- }
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » PHP获得跳转的真实地址实例
波比源码 » PHP获得跳转的真实地址实例
buy levaquin 500mg pills levofloxacin online
accutane tablet buy amoxil 250mg without prescription zithromax 250mg pill
tadalafil 10mg generika rezeptfrei kaufen tadalafil kaufen ohne rezept sildenafil 100mg kaufen ohne rezept
oral accutane amoxicillin 250mg uk ivermectin medication
buy provigil 100mg pill Cialis without prescription order acetazolamide generic
zyban over the counter atomoxetine generic seroquel over the counter
buy tadalafil 40mg online cheap purchase tadalafil sale order viagra 100mg without prescription
zithromax generic buy azithromycin 500mg generic gabapentin 100mg without prescription
buy chloroquine pill oral cenforce 100mg oral baricitinib
tamsulosin 0.4mg usa aldactone price buy spironolactone generic
fluconazole 200mg pills sildenafil for sale real viagra pills
viagra sildenafil 200mg sildenafil dosage lamictal buy online
order deltasone order amoxicillin 250mg online amoxil 500mg ca
viagra pill female cialis tadalafil tadalafil 40mg canada
cheap azithromycin prednisolone 10mg cost gabapentin cheap
order spiriva online order minocycline 50mg generic order terazosin 1mg online cheap
cialis tadalafil 40mg Buy cialis in usa poker online for fun
buy tadalafil 5mg sale Buy cialis on line cialis 20mg generic
best play money poker sites slots online slot game
roulette online with real money play poker online free purchase essays online
altace 5mg uk order amaryl 4mg online order etoricoxib 60mg sale
purchase olmesartan online order benicar order divalproex pill
mesalamine 400mg for sale asacol oral buy avapro 300mg pills
buy amoxil 500mg generic cost amoxil 500mg order stromectol
indocin 50mg ca order flomax 0.2mg order cenforce 50mg generic
order doxycycline without prescription order chloroquine 250mg online methylprednisolone without a doctor prescription
pepcid 20mg pill famotidine canada mirtazapine 15mg brand
order tadalafil 20mg for sale order amoxicillin generic buy trimox 500mg for sale
order metformin 500mg generic buy glucophage 500mg online purchase nolvadex for sale
ivermectin 3 medications for ed order deltasone 10mg without prescription
albuterol 4mg cost buy ventolin 2mg generic augmentin 1000mg drug
prednisolone 10mg generic cheap gabapentin sale furosemide pills
buy doxycycline 200mg generic purchase vibra-tabs generic zovirax 800mg drug
dutasteride uk order avodart sale order xenical online cheap
buy inderal sale buy coreg 25mg pills carvedilol 6.25mg us
buy avlosulfon 100mg pills tenormin usa buy tenormin without prescription
buy ezetimibe 10mg generic tetracycline 500mg without prescription order methotrexate 10mg pills