PHP递归创建目录函数
function mkdirs($path, $mode = 0777) //creates directory tree recursively
{
$dirs = explode(''/'',$path);
$pos = strrpos($path, ".");
if ($pos === false) { // note: three equal signs
// not found, means path ends in a dir not file
$subamount=0;
}
else {
$subamount=1;
}
for ($c=0;$c < count($dirs) - $subamount; $c++) {
$thispath="";
for ($cc=0; $cc <= $c; $cc++) {
$thispath.=$dirs[$cc].''/'';
}
if (!file_exists($thispath)) {
//print "$thispath<br>";
mkdir($thispath,$mode);
}
}
}
原函数中使用$GLOBALS["dirseparator"]我改成了''/''
function recur_mkdirs($path, $mode = 0777) //creates directory tree recursively
{
//$GLOBALS["dirseparator"]
$dirs = explode($GLOBALS["dirseparator"],$path);
$pos = strrpos($path, ".");
if ($pos === false) { // note: three equal signs
// not found, means path ends in a dir not file
$subamount=0;
}
else {
$subamount=1;
}
for ($c=0;$c < count($dirs) - $subamount; $c++) {
$thispath="";
for ($cc=0; $cc <= $c; $cc++) {
$thispath.=$dirs[$cc].$GLOBALS["dirseparator"];
}
if (!file_exists($thispath)) {
//print "$thispath<br>";
mkdir($thispath,$mode);
}
}}
感谢dxf218
我修正了其中一点点小小小的问题
<?php
/*
* FileName : cache.inc.php
* Link : [url]http://blog.111cn.net/dxflingxing/[/url]
* Author : dxflingxing
* Date : 2006-5-9
* Last Modified : 2006-5-16
* Version : 1.0.1
* Descrīption : Cache a page in file formart
* Notice : Make sure you cache file dir can be readed and wrote
*
* Thanks to : 小邪,barryonline(寒)
************************************************************
*
* Usage :
* # Cache active time half an hour
* # This Can Auotmatic make some none exist dirs
* # Or you can use an cache file in curent dir
* # The Usage Such as
* # $cache  
$d=array(
array("a",-20319),
array("ai",-20317),
array("an",-20304),
array("ang",-20295),
array("ao",-20292),
array("ba",-20283),
array("bai",-20265),
array("ban",-20257),
array("bang",-20242),
array("bao",-20230),
array("bei",-20051),
array("ben",-20036),
array("beng",-20032),
array("bi",-20026),
array("bian",-20002),
array("biao",-19990),
array("bie",-19986),
array("bin",-19982),
array("bing",-19976),
array("bo",-19805),
array("bu",-19784),
array("ca",-19775),
array("cai",-19774),
array("can",-19763),
array("cang",-19756),
array("cao",-19751),
array("ce",-19746),
array("ceng",-19741),
array("cha",-19739),
array("chai",-19728),
array("chan",-19725),
array("chang",-19715),
array("chao",-19540),
array("che",-19531),
array("chen",-19525),
array("cheng",-19515),
array("chi",-19500),
array("chong",-19484),
array("chou",-19479),
array("chu",-19467),
array("chuai",-19289),
array("chuan",-19288),
array("chuang",-19281),
array("chui",-19275),
array("chun",-19270),
array("chuo",-19263),
array("ci",-19261),
array("cong",-19249),
array("cou",-19243),
array("cu",-19242),
array("cuan",-19238),
array("cui",-19235),
array("cun",-19227),
array("cuo",-19224),
array("da",-19218),
array("dai",-19212),
array("dan",-19038),
array("dang",-19023),
array("dao",-19018),
array("de",-19006),
array("deng",-19003),
array("di",-18996),
array("dian",-18977
实际上是毫无作用的函数了~因为现在的域名商都很滑。很多域名只要注册了,就算不使用也会被默认指向一个域名商的网址。所以即便探过去,都会返回一个200值。 = = 这也是没办法的事。
<?php
$url = ''http://www.example.com'';
print_r(get_headers($url));
print_r(get_headers($url, 1));
?>
Array( [0] => HTTP/1.1 200 OK [1] => Date: Sat, 29 May 2004 12:28:13 GMT [2] => Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT [4] => ETag: "3f80f-1b6-3e1cb03b" [5] => Accept-Ranges: bytes [6] => Content-Length: 438 [7] => Connection: close [8] => Content-Type: text/html)Array( [0] => HTTP/1.1 200 OK [Date] => Sat, 29 May 2004 12:28:14 GMT [Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux) [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT [ETag] => "3f80f-1b6-3e1cb03b" [Accept-Ranges] => bytes [Content-Length] => 438 [Connection] => close [Content-Type] => text/html)
<?php
//$fp = file_get_contents("http://www.163.com");
$fp = fsockopen("www.selangsfer32.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />n";
exit;
}
?>
最近在看PHP静态分析与跨站脚本检测的东西,用的是维也纳大学一个博士生做出来的Pixy,这个东西是开源的,而且也作了好几年了,功能逐渐增强。现在这个3.0.3版本里边有225个程序,Checker是主程序,现在所有结果都是显示在命令行的,如果被检测程序大,结果很多,当然是个问题。而我要做的大概是将其显示到GUI中去,并且改进它本身呈鼓里边一些不足的地方。
从寒假就开始看他的程序,寒假里边没有怎么搞明白,又冷,手生冻疮了。回来以后,从头开始看吧,分析那一部分不是很明白,但是看到后来,检测漏洞的时候,我想暂时不管它存储的结构什么,反正都是Node之类的东西,看他是怎么检测的,有的细节地方那个暂时翻过去,结果感觉比前边analysze部分简单得多了,连那些存储结构什么的都明白些了。
当然也看他的论文,论文换了一个寒假看完,没弄明白,像Cfg这些东西在论文中有,但是显示不出来,没有直观的感觉,不爽。所以这两天忙着弄了个GUI界面来显示这个Cfg控制流图,麻烦了一点,不过总算是出来了,看看好像也没有多大问题,献丑在这里了。另外,本来是自己使用的,有的地方考虑不周也无所谓,自己再调调就行了。
共有3个文件,第一个是Coor.java,保存每个节点的坐标以及其子节点坐标:
package at.ac.tuwien.infosys.www.pixy;
import java.util.*;
public class Coor
{
private int x;
private int y;
private List<Coor> coors;
public Coor(int x, int y)
{
this.coors = new LinkedList<Coor>();
this.x = x;
this.y = y;
}
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
public List<Coor> getCoors()
{
return this.coors;
}
public void addCoor(Coor coor)
{
this.coors.add(coor);
}
public boolean equals(Coor coor)
{
if (coor.getX()==this.x && coor.getY()==y)
{
return true;
}
return false;
}
public boolean contains(Coor c)
{
for (Coor coor : this.coors)
{
if (coor.getX()==c.getX() && coor.getY()==c.getY())
{
return true;
}
}
return false;
}
}
第二个是DrawPanel.java,负责画图的组件:
package at.ac.tuwien.infosys.www.pixy;
import at.ac.tuwien.infosys.www.pixy.conversion.Cfg;
import at.ac.tuwien.infosys.www.pixy.conversion.nodes.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class DrawPanel extends JPanel
{
private java.util.List<CfgNode> cfgList;
private java.util.List<Coor> coorList;
/** Creates a new instance of OvalJPanel */
public DrawPanel(java.util.List<CfgNode> cfgList, java.util.List<Coor> coorList)
{
this.cfgList = cfgList;
this.coorList = coorList;
}
//在面板上绘制图形
public void paintComponent(Graphics g)
{
for (int i=0 ;i<this.cfgList.size() ;i++ )
{
CfgNode cfgNode = this.cfgList.get(i);
Coor coor = this.coorList.get(i);
int x = coor.getX();
int y = coor.getY();
g.setColor(Color.red);
g.drawOval(x-50, y-15, 100, 30);
g.setColor(Color.blue);
g.drawString(cfgNode.toString(), x-30, y-5);
g.drawString("Loc :" + String.valueOf(cfgNode.getOrigLineno()), x, y+10);
java.util.List<Coor> coors = coor.getCoors();
for (Coor c : coors)
{
int cx = c.getX();
int cy = c.getY();
g.setColor(Color.black);
if (c.equals(coor))
{
g.setColor(Color.yellow);
}
g.drawLine(x, y+15, cx, cy-15);
}
}
}
}
第三个是Draw.java,主控制组件,只需要在Checker中调用该类,传以适当参数(Cfg),就可以了。
package at.ac.tuwien.infosys.www.pixy;
import at.ac.tuwien.infosys.www.pixy.conversion.Cfg;
import at.ac.tuwien.infosys.www.pixy.conversion.nodes.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
/**
*
* @author Administrator
*/
public class Draw {
//声明框架
private JFrame frame = new JFrame("Control Flow Graph");
//声明书签面板
private DrawPanel draw;
private Cfg cfg;
private Map<CfgNode, Coor> map;
private java.util.List<CfgNode> cfgList;
private java.util.List<Coor> coorList;
private int startX = 50;
private int startY = 30;
/** Creates a new instance of TabbedJFrame */
public Draw(Cfg cfg) {
//this.map = new TreeMap<CfgNode, Coor>();
this.cfgList = new LinkedList<CfgNode>();
this.coorList = new LinkedList<Coor>();
this.cfg = cfg;
}
public void show()
{
frame.add(new JScrollPane(new DrawPanel(this.cfgList, this.coorList)), BorderLayout.CENTER);
frame.setSize(1000, 1000);
frame.setLocation(50, 50);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* 将Cfg转换为cfgList和coorList.
*/
public void convert()
{
CfgNode node = this.cfg.getHead();
int size = this.cfg.size();
Coor coor = new Coor(startX, startY);
this.cfgList.add(node);
this.coorList.add(coor);
System.out.println(size);
java.util.List<CfgNode> noded = new LinkedList<CfgNode>();
for (int i=0 ;i<size ;i++ )
{
int n = i;
if (noded.contains(node))
{
n = -1;
for (CfgNode cfgNode : this.cfgList )
{
n++;
if (noded.contains(cfgNode))
{
continue;
}
node = cfgNode;
break;
}
}
noded.add(node);//为了上边的if判断好做,故在此向noded中添加
java.util.List<CfgNode> list = node.getSuccessors();
int len = list.size();
if (len == 0)
{
continue;
}
int k = 0;
coor = this.coorList.get(this.cfgList.indexOf(node));
startY = coor.getY() + 60;
for (CfgNode cfgNode : list)
{
startX = coor.getX() + k*250;
k++;
if (this.cfgList.contains(cfgNode))
{
Coor c = (Coor)this.coorList.get(this.cfgList.indexOf(cfgNode));
if (!coor.contains(c))
{
coor.addCoor(c);
}
continue;
}
coor.addCoor(new Coor(startX, startY));
this.cfgList.add(cfgNode);
this.coorList.add(new Coor(startX, startY));
}
node = list.get(0);//这里取到的CfgNode可能已经分析过了,通过上边的if判断可以从cfgList中另外取一个。
}
}
public void setStartX(int x)
{
this.startX = x;
}
public void setStartY(int y)
{
this.startY = y;
}
public int getStartX()
{
return this.startX;
}
public int getStartY()
{
return this.startY;
}
public void dump()
{
System.out.println("------------------");
for (int i=0 ; i<this.cfgList.size(); i++)
{
CfgNode cfgNode = this.cfgList.get(i);
Coor coor = this.coorList.get(i);
System.out.println(cfgNode.toString() + " "/* + cfgNode.toString()*/ +" " + coor.getX() + " " + coor.getY() + " " + coor.getCoors().size());
}
System.out.println("------------------");
}
public void dumpMap()
{
java.util.List<CfgNode> list = this.cfg.dfPreOrder();
System.out.println("******************");
for (CfgNode node : list)
{
System.out.println(" " + node.toString() + " " + node.getSuccessors().size());
}
System.out.println("******************");
}
public static void main(String [] args)
{
// new Draw();
}
}
可能这个项目还会做很久,中间会不会有些心得继续放到这个懒得管的空间中来呢,期待着。
相关文章
- eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
- 在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
Python astype(np.float)函数使用方法解析
这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08- 这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
- 本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
- 下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 今天小编就为大家分享一篇解决Pycharm的项目目录突然消失的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-04-22
- CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
- 这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
Android开发中findViewById()函数用法与简化
findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20- strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
- 这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
PHP函数分享之curl方式取得数据、模拟登陆、POST数据
废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07- Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
- 这篇文章主要介绍了JS创建Tag标签的方法,结合具体实例形式分析了javascript动态操作页面HTML元素实现tag标签功能的步骤与相关操作技巧,需要的朋友可以参考下...2017-06-15
- free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
- 1.创建div元素: Javascript代码 复制代码 代码如下: <scripttypescripttype="text/javascript"> functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv.innerHTML="Testcreateadiveleme...2013-10-13
- PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。由于 strip_tags() 无法实际验证 HTML,不完整或者破损标签将导致更多的数...2014-05-31
- 分享一个PHP加密解密的函数,此函数实现了对部分变量值的加密的功能。 加密代码如下: /* *功能:对字符串进行加密处理 *参数一:需要加密的内容 *参数二:密钥 */ function passport_encrypt($str,$key){ //加密函数 srand(...2015-10-30
SQL Server中row_number函数的常见用法示例详解
这篇文章主要给大家介绍了关于SQL Server中row_number函数的常见用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08