.
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'];
代码如下 |
复制代码 |
function funcurl($str)//url正则表达试
{
return (preg_match("/^http://[a-za-z0-9]+.[a-za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$/",$str))?true:false;
} |
代码如下 |
复制代码 |
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(); |
这是一款很简单的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 );
/*
& (和) 转成 &
" (双引号) 转成 "
< (小于) 转成 <
> (大于) 转成 >
此函式只转换上面的特殊字元,并不会全部转换成 html 所定的 ascii 转换
*/
//输出
html_entity_decode($str);
/*
于html_entity_decode在大多数情况下是与htmlspecialchars htmlentities配合使用的
*/
标签:[!--infotagslink--]