php获取当前页面【不】完整url地址,请看代码

djskyzhang 2014-06-26 11:08:28
原代码
function parseurl($url, $text, $scheme) {
global $_G;
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
$url = $matches[0];
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
}
return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == 'www.') {
$url = 'http://'.$url;
}
$url = !$scheme ? $_G['siteurl'].$url : $url;
return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
}
}

改后。

function parseurl($url, $text, $scheme) {

global $_G;

if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {

$url = $matches[0];

$length = 200;

if(strlen($url) > $length) {

$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));

}

return '<a href="http://localhost/go.php?url='.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';

} else {

$url = substr($url, 1);

if(substr(strtolower($url), 0, 4) == 'www.') {

$url = 'http://'.$url;

}

$url = !$scheme ? $_G['siteurl'].$url : $url;


return '<a href="http://localhost/go.php?url='.$url.'" target="_blank">'.$text.'</a>';

}

}

我在GO.PHP跳转代码里加

<script>
function goURL( goUrlStr ) {
if ( typeof(goUrlStr) != 'undefined') {
var isIe=(document.all)? true : false;
if(isIe) {
var linka = document.createElement('a');
linka.href = goUrlStr;
document.body.appendChild(linka);
linka.click();
} else {
window.location = goUrlStr;
}
}
return true;
}
</script>
<body><script>goURL('这个是地址位置我改怎么加http://localhost/go.php?url=后面的地址在这呀。');</script><body>

要不然http://localhost/go.php?url=在显示后面的地址 会出现重向循环。只有要http://localhost/go.php?url=后面的地址了。

高手们谢谢你们了

下面是完整的地址获取

<script>
function goURL( goUrlStr ) {
if ( typeof(goUrlStr) != 'undefined') {
var isIe=(document.all)? true : false;
if(isIe) {
var linka = document.createElement('a');
linka.href = goUrlStr;
document.body.appendChild(linka);
linka.click();
} else {
window.location = goUrlStr;
}
}
return true;
}
</script>
<body><script>goURL('<?php
function get_page_url(){
$url = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'];
$url .= isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
return $url;
}
$target = get_page_url();
header("location:".$target);
?>
');</script><body>
获取后的地址http://localhost/go.php?url=http://redirect.simba.taobao.com/rd?w=aitaobao_auctionlist&f=http%3A%2F%2Fai.taobao.com%2Fauction%2Fidetail.htm%3Fe%3D9yJqNV6xpsTghojqVNxKsXYlGzf9L3QKAdcPAzm7QvSLltG5xFicOVsrMD406QbSxN35oEuRTJfz8%252FzzUUAa8ZxtFGeD4d%252F1L7cKmKx7yws%253D%26ptype%3D100016%26from%3Daitaobao%23app_pvid%3D200_10.246.41.109_308_1402996372125&k=b9ae9a9259ca89f8&c=un&b=3_4&p=mm_0_0_0&pvid=100_10.238.192.12_24338_1403003417786149925
我想去掉http://localhost/go.php?url=自动显示后面的地址怎么改呀。,
...全文
134 回复 打赏 收藏 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,984

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧