冰豆网

分享网络精彩
bingdou.com.cn

一款简单的php 延时跳转代码

时间:2021-04-18加入收藏

Web开发中经常会遇到页面跳转或延时跳转的需求,掌握各种页面跳转方式非常必要;以下是舍力总结有用PHP实现跳转的方法,例子皆为三秒后跳转到指定的页面。

<?php
$url=$_SERVER["HTTP_REFERER"];
$str=str_replace("http://","",$url);
$str=str_replace("https://","",$url);
$strdomain = explode("/",$str);
$domain=$strdomain[0];
if($domain==''){
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');//防止快速刷新
session_start();
$seconds = '30'; //时间段[秒]
$refresh = '3'; //刷新次数
//设置监控变量
$cur_time = time();
if(isset($_SESSION['last_time'])){$_SESSION['refresh_times'] += 1;
}else{$_SESSION['refresh_times'] = 1;$_SESSION['last_time'] = $cur_time;}
//处理监控结果
if($cur_time - $_SESSION['last_time'] < $seconds){if($_SESSION['refresh_times'] >= $refresh){
//跳转至攻击者服务器地址
header(sprintf('Location:%s', 'http://127.0.0.1'));exit('Access Denied');}
}else{$_SESSION['refresh_times'] = 0;$_SESSION['last_time'] = $cur_time;}
echo 'Access Denied';exit;}
//跳转结果
$urlhttp= strtolower(substr($_REQUEST["url"],0,7));
$urlhttps=strtolower(substr($_REQUEST["url"],0,8));
if($urlhttp=='http://'||$urlhttps=='https://'){$slurl=$_REQUEST["url"];}else{$slurl='http://'.$_REQUEST["url"];}
$web=preg_replace('/(http:\/\/|https:\/\/|)*/','',$_REQUEST["url"]);
header("HTTP/1.1 301 Moved Permanently");
header("Refresh:3;url=".$slurl."");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=11,IE=10,IE=9,IE=8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
<title>网页3秒将跳转到<?php echo $web;?></title>
<style type="text/css">
<!--
body{background-color:#F7F7F7;font-family:Arial;line-height:150%;}
.main{background-color:#FFFFFF;font-size:12px;color:#666666;max-width:650px;margin:60px auto 0px;border-radius:10px;padding:30px 10px;list-style:none;border:#DFDFDF 1px solid; overflow:hidden;}
.main h6{line-height:30px;font-size:18px;margin:5px 20px;}
.main p{line-height:25px;font-size:14px;margin:5px 20px;}
-->
</style>
</head>
<body>
<div class="main">
<h6>您所访问的页面将跳转到第三方网站,可能会有安全风险,望知悉!!!</h6>
<p>3秒后将自动为你跳转到<?php echo $web;?></p>
<div style="clear:both;text-align:center;font-size:14px; margin-top:50px;">本页由冰豆网提供</div>
</div>
</body>
</html>

使用方法:建立一个文件夹例如go,然后在文件夹中创立一个index.php文件,把上面的代码放入到这个index.php文件中即可。
代码中加入了不能直接打开和简单的防刷新代码。
格式:www.bingdou.com.cn/go/?url=www.3600.win

打 赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

TGA: php 技巧

分享到:


官方微信二维码冰豆网官方微信公众号