使用iconv方法进行编码转换。在windows平台下面可以正常的工作(本地环境使用的win7),但是在linux环境下面iconv总是返回false(测试环境使用的linux)。
参考phpinfo的信息,iconv模块也已经正确加载。
google一下。原来才知道,原来在linux版本下iconv这个方法还是有点下下问题的。
csdn上的一个网友给出的解决方案为:
一种方法是把iconv换成 mb_convert_encoding
另一种方法是修改iconv 的实现,从glibc 改为libiconv
搞了半天,烦躁!
有朋友碰到的话,也可以这么解决了
按照该网友提供的第一个方法,将iconv方法修改为使用mb_convert_encoding,搞定。。
多谢该网友提供的解决方案。
下载:ftp://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.8.tar.gz
安装:
#cp libiconv-1.8.tar.gz /usr/local/src
#tar zxvf lib*
#./configure --prefix=/usr/local/libiconv
#make
#make install
编译php
#./configure --prefix=/usr/local/php4.3.2 --with-iconv=/usr/local/libiconv/
使用的简单例子:
<?php
echo iconv("gb2312","ISO-8859-1","我们");
一款入门级的ajax用户登录代码,有需要的初学者可以参考一下,
login.html
代码如下 |
复制代码 |
<input name=username type=text /> 用户名
<input name=password type=password />密码
<input type=button value=提交 />
|
js代码
代码如下 |
复制代码 |
function chk_login(form){
var username=form.username;
var password=form.password;
if(username.value == ""){
alert("用户名不能为空");
username.focus();
return false;
}
if(password.value == ""){
alert("密码不能为空");
password.focus();
return false;
}
var url = 'login_chk.php?username='+username.value+'&password='+password.value;
xmlhttp.open('get',url,true);
//为什么下面加了下面注释掉的代码后,会没反应了,没加就有反应,我的php文件路径都是正确的,也有引入xmlhttprequest.js
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
var msg = xmlhttp.responseText;
if(msg == "1"){
alert("登陆成功");
window.location='index.php?name='+username.value;
}else if((msg == "2"){
alert("登陆用户名或密码错误");
}else{
alert(msg);
}
}
}
}
xmlhttp.send(null);*/
}
ogin
|
_chk.php
因为是测试文件所以没读取数据库了,这里就不写了有需要的朋友可以自己加上读数据库用户名记录,如果存在就返回1就可以了。
有关教程可以参考
http://www.111cn.net/phper/php-cy/34654.htm
http://www.111cn.net/phper/21/46169c59dabdf0501de3d9ac9653e096.htm
该函数将 URL 和 E-mail 地址字符串转换为可点击的超级链接。
代码如下 |
复制代码 |
function makeClickableLinks($text)
{
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="1">1</a>', $text); $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)', '1<a href="http://2">2</a>', $text); $text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})', '<a href="mailto:1">1</a>', $text);
return $text;
}
|
提供一款简单实现的连接类是利用php 构造函数自动创建连接与删除操作,有需要的朋友可以参考。
代码如下 |
复制代码 |
class mysql {
private $db_host; //数据库主机
private $db_user; //数据库用户名
private $db_pwd; //数据库用户名密码
private $db_database; //数据库名
private $conn; //数据库连接标识;
private $result; //执行query命令的结果资源标识
private $sql; //sql执行语句
private $row; //返回的条目数
private $coding; //数据库编码,GBK,UTF8,gb2312
private $bulletin = true; //是否开启错误记录
private $show_error = true; //测试阶段,显示所有错误,具有安全隐患,默认关闭
private $is_error = false; //发现错误是否立即终止,默认true,建议不启用,因为当有问题时用户什么也看不到是很苦恼的
/*构造函数*/
public function __construct($db_host, $db_user, $db_pwd, $db_database, $conn, $coding) {
$this->db_host = $db_host;
$this->db_user = $db_user;
$this->db_pwd = $db_pwd;
$this->db_database = $db_database;
$this->conn = $conn;
$this->coding = $coding;
$this->connect();
}
/*数据库连接*/
public function connect() {
if ($this->conn == "pconn") {
//永久链接
$this->conn = mysql_pconnect($this->db_host, $this->db_user, $this->db_pwd);
} else {
//即使链接
$this->conn = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
}
if (!mysql_select_db($this->db_database, $this->conn)) {
if ($this->show_error) {
$this->show_error("数据库不可用:", $this->db_database);
}
}
mysql_query("SET NAMES $this->coding");
}
/*数据库执行语句,可执行查询添加修改删除等任何sql语句*/
public function query($sql) {
if ($sql == "") {
$this->show_error("SQL语句错误:", "SQL查询语句为空");
}
$this->sql = $sql;
$result = mysql_query($this->sql, $this->conn);
if (!$result) {
//调试中使用,sql语句出错时会自动打印出来
if ($this->show_error) {
$this->show_error("错误SQL语句:", $this->sql);
}
} else {
$this->result = $result;
}
return $this->result;
}
/*创建添加新的数据库*/
public function create_database($database_name) {
$database = $database_name;
$sqlDatabase = 'create database ' . $database;
$this->query($sqlDatabase);
}
|
一款讲得非常详细的登录代码,对php入门者有很大的帮助,有需要的朋友可以免费查看。
效果图。
index.php教程
代码如下 |
复制代码 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>系统登录</title>
<link href="css教程.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="box">
<div id="denglu">
<div id="pic"> 系统后台登陆</div>
<form action="check.php" method="post">
<p>用户名:
<input type="text" name="name" id="name" />
<span class="must">*</span></p>
<p>密 码:
<input name="password" type="password" id="password" />
<span class="must">*</span></p>
<p>验证码:
<input name="check" type="text" id="check" size="8" />
<img" width=100% src="piccheck.php" /> <span class="must">*</span></p>
<p class="form_button">
<input type="submit" name="sub" id="sub" value="登陆" />
<input type="reset" name="unsub" id="unsub" value="取消" />
</p>
</form>
</div>
</div>
</body>
</html>
|
数据库教程连接 connect.php
代码如下 |
复制代码 |
<?php
$connect=mysql教程_connect("localhost","root","")or die("服务器连接失败");
mysql_select_db("test",$connect)or die("没有建立相应的数据库");
$sql="select * from admin";
?>
|
图片验证码 piccheck.php
代码如下 |
复制代码 |
<?php
/*
* Created on 2011-8-10
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclips教程e - PHP - Code Templates
*/
session_start();
$code=rand(0,9).dechex(rand(10,15)).rand(0,9).dechex(rand(10,15));
$_SESSION[pic]=$code;
$image=imagecreatetruecolor(50,18);
$color=imagecolorallocate($image,0,0,0);//第一次使用调色板,会设为背景颜色
$colortext=imagecolorallocate($image,rand(100,255),rand(100,255),rand(100,255));
imagestring($image,10,rand(1,15),rand(1,5),$code,$colortext);
imagegif($image);
?> |
css.css文件
代码如下 |
复制代码 |
@charset "utf-8";
/* CSS Document */
body {
background-color: #9CF;
text-align: left;
}
#denglu {
width: 400px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
background-image: url(images/login.gif);
background-repeat: no-repeat;
height: 320px;
text-indent: 6px;
}
#box #denglu form {
position: relative;
top: 50px;
left: 10px;
width: 92%;
}
.must {
color: #F00;
font-size: 12px;
}
#box #denglu #pic {
background-image: url(images/dot1.gif);
background-repeat: no-repeat;
height: 20px;
width: 100px;
font-size: 12px;
color: #F00;
text-align: left;
line-height: 18px;
left: 10px;
top: 30px;
position: relative;
}
|
标签:[!--infotagslink--]