douyan8961 2013-02-05 21:21
浏览 16

PHP不转发重定向

I am having some issues with PHP detecting http:// containing and non-http:// containing links from database and referencing user based on them here is the code;

$url = $_GET['short'];

$route_url = mysql_result(mysql_query('SELECT original_url FROM ' . DB_TABLE . ' WHERE short_url = "' . mysql_real_escape_string($url) . '"'));

mysql_query('UPDATE ' . DB_TABLE . ' SET refferals = refferals + 1 WHERE short_url = "' . mysql_real_escape_string($url) . '"');

if(preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i", $route_url)) { 
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $route_url);
} else {
$protocol = "http://";
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $protocol.$route_url);
}
mysql_close();
exit;

Can some on tell me what I am doing wrong and how to fix it, so both http:// and non-http:// (google.com) work with redirect

  • 写回答

1条回答 默认 最新

  • douyuefu1372 2013-02-05 21:44
    关注

    As suggested by @Supericy to strip http:// from initial URL submission I added following

    function http($url) {
       $disallowed = array('http://', 'https://');
       foreach($disallowed as $d) {
          if(strpos($url, $d) === 0) {
             return str_replace($d, '', $url);
          }
       }
       return $url;
    }
    

    And now the routing works just fine

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化