首页 > 编程技术 > php

php类,构造函数 静态变量实例

发布时间:2016-11-25 15:11

 代码如下 复制代码
class dispatcher{
 private $config;
 public static $o;
 function __construct(){
  echo 'sss';
 }
 public static function getinstance(){
  if (!self::$o){
   self::$o = new dispatcher();
  }
  self::$o;
 }
}
new dispatcher();

.
var yu_yan = navigator.language || navigator.userlanguage;
if(yu_yan.substr(0, 3) == "zh-"){
window.location='sorry.php教程';
}

php

echo $_server['http_accept_language'];

获取所有信息

echo $_server['http_user_agent'];

这是一款很简单的php入门级用户登录代码,如果用户登录成功了就会自动跳到指定的页面,否则就会返回登录页面,登录原是是判断用户输入的用户名与密码在数据库中是否在存了,如果是就保存信息存在session否提示登录出错。

#
# 表的结构 `admin`
#

 代码如下 复制代码
create table `admin` (
  `id` mediumint(4) not null auto_increment,
  `us` varchar(50) not null default '',
  `pas` varchar(250) not null default '',
  unique key `id` (`id`)
) type=myisam comment='登录' auto_increment=2 ;

#
# 导出表中的数据 `admin`
#

insert into `admin` (`id`, `us`, `pas`) values (1, 'admin', 'admin');
*/?>

登录html页面代码

 代码如下 复制代码

<html>
<head>
<title>登录</title>
<meta http-equiv="content" content="text/html; charset=gb2312">
<link href="css教程.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
if ($http_cookie_vars["admin"]) {
 header("location:admin.php");
}
?>
<form method="post" action="admin_logins.php">
<table width="40%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolorlight="#cccccc" bordercolordark="#f7f7f7" class="css">
<tr>
<td bgcolor="#f7f7f7" colspan="2" align="center"><b>管理员登录</b></td>
<tr>
<tr>
<td>用户名</td>
<td><input type="text" name="us" size="30" maxlength="30" class="inputt"></td>
<tr>
<tr>
<td>密码</td>
<td><input type="password" name="pas" size="34" class="inputt" maxlength="40"></td>
</tr>
<tr>
<td bgcolor="#f7f7f7" colspan="2"><div align="center">
  <input type="submit" name="submit" class="inputt" value="进入">
</div></td>
</tr>
</table>
</form>
</body>
</html>

php代码

 代码如下 复制代码

<?php
$db=@mysql_connect("localhost","root","micronsky.net") or die("数据库连接也错");
mysql_select_db("vote",$db);
$submit=$_post["submit"];
$us=$_post["us"];
$pas=$_post["pas"];
if ($submit) {
 $result=mysql_query("select us,pas from admin where us='$us'",$db);
 if ($myrow=mysql_fetch_array($result)) {
  if ($pas==$myrow["pas"]) {
   setcookie("admin",$us,time()+3600);
   header("location:admin.php");
  }
  else {
   echo "<script>alert('密码不正确');history.back();</script>";
  }
 }
  else {
   echo "<script>alert('用户名不存在');history.back();</script>";
  }

 }
?>

$str ="<a >fdafsa''&#x</a>";
echo htmlspecialchars( $str );
/*
& (和) 转成 &amp;
" (双引号) 转成 &quot;
< (小于) 转成 &lt;
> (大于) 转成 &gt;
此函式只转换上面的特殊字元,并不会全部转换成 html 所定的 ascii 转换

*/

//输出

html_entity_decode($str);

/*
于html_entity_decode在大多数情况下是与htmlspecialchars htmlentities配合使用的

*/

匹配首尾空白字符的正则表达式:^\\s*|\\s*$ 评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式

匹配首尾空白字符的正则表达式:^s*|s*$
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式


$action = trim($_get['action']);
if($action == "sub")
{
    $str = $_post['dir'];   
    //if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."a-za-z0-9_]+$/",$str)) //gb2312汉字字母数字下划线正则表达式
    if(!preg_match("/^[x{4e00}-x{9fa5}a-za-z0-9_]+$/u",$str))   //utf-8汉字字母数字下划线正则表达式
    {  
        echo "<font color=red>您输入的[".$str."]含有违法字符</font>";  
    }
    else
    {
        echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>";  
    }
}
?>
<form method="post" action="">
输入字符(数字,字母,汉字,下划线):
    <input type="text" name="dir" value="">
    <input type="submit" value="提交">
</form>


匹配网址url的正则表达式:[a-za-z]+://[^s]*
评注:网上流传的版本功能很有限,上面这个基本可以满足需求
匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-za-z][a-za-z0-9_]{4,15}$
评注:表单验证时很实用
匹配国内电话号码:d{3}-d{8}|d{4}-d{7}
评注:匹配形式如 0511-4405222 或 021-87888822
匹配腾讯qq号:[1-9][0-9]{4,}
评注:腾讯qq号从10000开始
匹配中国邮政编码:[1-9]d{5}(?!d)
评注:中国邮政编码为6位数字
匹配身份证:d{15}|d{18}
评注:中国的身份证为15位或18位
匹配ip地址:d+.d+.d+.d+
评注:提取ip地址时有用

标签:[!--infotagslink--]

您可能感兴趣的文章: