当前位置: 编程技术>php
本页文章导读:
▪在线增减.htpasswd内的用户
在线增减.htpasswd内的用户 <?php include("./class.Htpasswd.php3"); /* 请修改此.htpasswd文件路径 */ $htpasswdfile = "/usr2/amitc/.htpasswd"; // 此行请勿修改 echo '<FORM ACTION="'.$PHP_SELF . '" METHOD=POST.........
▪将OICQ数据转成MYSQL数据
This file is /tmp/phpBeoJQ5 . ################# You can copy this code to test ################# <? include("include/dbclass.inc"); //可以用 MYSQL.INC 类代替测试 $q = new DB_Sql; $db = $q->Database; //define the database.........
▪PHP中一个控制字符串输出的函数
// php 中 一个控制字符串输出的函数(中英文),每行显示多少字数,避免英文的影响 // $str 字符串 // $len 每行显示的字数(汉字×2) function rep($str,$len) { $strlen=strlen($str); .........
[1]在线增减.htpasswd内的用户
来源: 互联网 发布时间: 2013-11-30
在线增减.htpasswd内的用户
<?php
include("./class.Htpasswd.php3");
/* 请修改此.htpasswd文件路径
*/
$htpasswdfile = "/usr2/amitc/.htpasswd";
// 此行请勿修改
echo '<FORM ACTION="'.$PHP_SELF . '" METHOD=POST>';
?>
<Table BORDER><TR>
<TD>Username: </TD>
<TD><INPUT TYPE=text name="username"></TD>
</TR><TR>
<TD>Password: </TD>
<TD><INPUT TYPE=text name="password"></TD>
</TR><TR>
<TD>
<INPUT TYPE=radio NAME=doop VALUE="verify" CHECKED> Verify Password <BR>
<INPUT TYPE=radio NAME=doop VALUE="add" > 加入新用户<BR>
<INPUT TYPE=radio NAME=doop VALUE="delete" > 删除用户 <BR>
<INPUT TYPE=radio NAME=doop VALUE="change" > 更改密码 <BR>
</TD>
<TD>
<INPUT TYPE=submit name="operation">
</TD></TR>
</TR>
</TABLE>
</FORM>
<?php
if(!isset($operation)) {
}
else {
echo "<FONT COLOR=RED> <HR>";
echo "您刚进行了此项操作,请核查 <BR><HR>";
echo "您要对用户 $username 及密码 $password 进行 = [$doop] <BR>";
$handle = new Htpasswd($htpasswdfile);
switch ($doop) {
case 'add':
print "用户<BR>";
$retval = $handle->addUser($username, $password);
if($retval) {
print "用户 [$username] 加入成功!<BR>";
} else {
print "加入用户 [$username] 失败.<BR>";
}
break;
case 'change':
print '修改密码<BR>';
$retval = $handle->changePass($username, $password);
if($retval) {
print "[$username] 的密码修改成功.<BR>";
} else {
print "[$username] 的密码修改失败.<BR>";
}
break;
case 'delete':
print '删除用户<BR>';
$retval = $handle->deleteUser($username);
if($retval) {
print "[$username] 被删除.<BR>";
} else {
print "删除 [$username]时发生错误.<BR>";
}
break;
case 'verify':
print 'Code to verify user's password<BR>';
$retval = $handle->verifyUser($username, $password);
if($retval) {
print "[$username] verifies okay with password [$password]<BR>";
} else {
print "Verify Error for [$username] with [$password] (wrong password or user doesn't exist!) <BR>";
}
break;
default:
print '您要中断? <BR>';
}
echo "</FONT>";
}
?>
<?php
include("./class.Htpasswd.php3");
/* 请修改此.htpasswd文件路径
*/
$htpasswdfile = "/usr2/amitc/.htpasswd";
// 此行请勿修改
echo '<FORM ACTION="'.$PHP_SELF . '" METHOD=POST>';
?>
<Table BORDER><TR>
<TD>Username: </TD>
<TD><INPUT TYPE=text name="username"></TD>
</TR><TR>
<TD>Password: </TD>
<TD><INPUT TYPE=text name="password"></TD>
</TR><TR>
<TD>
<INPUT TYPE=radio NAME=doop VALUE="verify" CHECKED> Verify Password <BR>
<INPUT TYPE=radio NAME=doop VALUE="add" > 加入新用户<BR>
<INPUT TYPE=radio NAME=doop VALUE="delete" > 删除用户 <BR>
<INPUT TYPE=radio NAME=doop VALUE="change" > 更改密码 <BR>
</TD>
<TD>
<INPUT TYPE=submit name="operation">
</TD></TR>
</TR>
</TABLE>
</FORM>
<?php
if(!isset($operation)) {
}
else {
echo "<FONT COLOR=RED> <HR>";
echo "您刚进行了此项操作,请核查 <BR><HR>";
echo "您要对用户 $username 及密码 $password 进行 = [$doop] <BR>";
$handle = new Htpasswd($htpasswdfile);
switch ($doop) {
case 'add':
print "用户<BR>";
$retval = $handle->addUser($username, $password);
if($retval) {
print "用户 [$username] 加入成功!<BR>";
} else {
print "加入用户 [$username] 失败.<BR>";
}
break;
case 'change':
print '修改密码<BR>';
$retval = $handle->changePass($username, $password);
if($retval) {
print "[$username] 的密码修改成功.<BR>";
} else {
print "[$username] 的密码修改失败.<BR>";
}
break;
case 'delete':
print '删除用户<BR>';
$retval = $handle->deleteUser($username);
if($retval) {
print "[$username] 被删除.<BR>";
} else {
print "删除 [$username]时发生错误.<BR>";
}
break;
case 'verify':
print 'Code to verify user's password<BR>';
$retval = $handle->verifyUser($username, $password);
if($retval) {
print "[$username] verifies okay with password [$password]<BR>";
} else {
print "Verify Error for [$username] with [$password] (wrong password or user doesn't exist!) <BR>";
}
break;
default:
print '您要中断? <BR>';
}
echo "</FONT>";
}
?>
[2]将OICQ数据转成MYSQL数据
来源: 互联网 发布时间: 2013-11-30
This file is /tmp/phpBeoJQ5 .
################# You can copy this code to test #################
<?
include("include/dbclass.inc"); //可以用 MYSQL.INC 类代替测试
$q = new DB_Sql;
$db = $q->Database; //define the database
mysql_connect('localhost:3306',$q->User,$q->Password);
?>
<form method="post" action="/blog_article/</php echo $PHP_SELF;/gt;.html"
enctype="multipart/form-data">
<input type="file" name="csv_file"
value="<?php echo $csv_file;?>">
terminated by <input type="text" name="terminated"
value="," size=2><p>
Which table you want to insert ?
<?php show_table($db,$table); ?><p>
<input type="submit" name="submit" value="go">
</form>
<?php
function show_field($db,$table,$num,$selected_field) {
$result = mysql_db_query($db, "SHOW KEYS FROM $table") or mysql_die();
$primary = "";
while ($row = mysql_fetch_array($result))
if ($row["Key_name"] == "PRIMARY")
$primary .= "$row[Column_name], ";
$result = mysql_db_query($db, "SHOW FIELDS FROM $table");
if (!$result) {
mysql_die();
}
else {
echo "<select name=field$num>n";
while ($row= mysql_fetch_array($result)) {
$selected = ($selected_field == $row["Field"]) ? "selected" : "";
echo "<option value=" . $row["Field"] . " $selected>" .
$row["Field"] . "</option>n";
}
echo "</select>nn";
}
}
function show_table($db,$selected_table) {
$tables = mysql_list_tables($db);
$num_tables = @mysql_numrows($tables);
if ($num_tables == 0) {
echo "no table yet";
}
else {
$i = 0;
echo "<select name=table>n";
while ($i < $num_tables) {
$table = mysql_tablename($tables, $i);
$selected = ($selected_table == $table) ? "selected" : "";
echo "<option value=$table $selected>$table</option>n";
$i++;
}
echo "</select>nn";
}
}
if ($submit) {
if(!empty($csv_file) && $csv_file != "none") {
//$csv_file = stripslashes($csv_file);
$fp = fopen($csv_file, "r");
// show first line of the csv file to select dababase table and its fields
echo "<form method=post action=$PHP_SELF>";
$csv_data = fgetcsv($fp, 2000, "$terminated");
$num = count($csv_data);
for ( $c=0; $c<$num; $c++ ) {
$field_name[$c] = $csv_data[$c];
echo $field_name[$c] . " n";
$table_field_name = "field$c";
show_field($db,$table,$c,$$table_field_name);
echo "<br>";
}
// copy the tmp file for next use
$dest = "/tmp/csv_file.csv";
copy($csv_file,$dest);
echo "<input type=hidden name=csv_file value=$dest>n" .
"<input type=hidden name=table value=$table>n" .
"<input type=hidden name=terminated value=$terminated>n" .
"<input type=submit name=submit value=ok></form><p>n";
// when click 'ok' button ,start insert data
if ($submit == "ok") {
$NO = 1;
while ($csv_data = fgetcsv($fp, 2000, "$terminated")) {
//$num = count($csv_data);
for ( $c=0; $c<$num; $c++ ) {
$table_field_name = "field$c";
$first_3 = substr($$table_field_name, 0, 3);
$first_2 = substr($$table_field_name, 0, 2);
$val_tmp = ($first_3 == "fid" || $first_3 == "int"
|| $first_2 == "id") ?
$csv_data[$c] : "'" . $csv_data[$c] . "'";
$val .= $val_tmp . ",";
$var .= $$table_field_name . ",";
}
$val = substr($val, 0, -1);
$var = substr($var, 0, -1);
$query = "INSERT INTO $table ($var) VALUES ($val)";
$val = "";
$var = "";
$q->query($query);
echo "NO. $NO $query<p>";
$NO++;
}
fclose($fp);
}
}
}
?>
################# You can copy this code to test #################
<?
include("include/dbclass.inc"); //可以用 MYSQL.INC 类代替测试
$q = new DB_Sql;
$db = $q->Database; //define the database
mysql_connect('localhost:3306',$q->User,$q->Password);
?>
<form method="post" action="/blog_article/</php echo $PHP_SELF;/gt;.html"
enctype="multipart/form-data">
<input type="file" name="csv_file"
value="<?php echo $csv_file;?>">
terminated by <input type="text" name="terminated"
value="," size=2><p>
Which table you want to insert ?
<?php show_table($db,$table); ?><p>
<input type="submit" name="submit" value="go">
</form>
<?php
function show_field($db,$table,$num,$selected_field) {
$result = mysql_db_query($db, "SHOW KEYS FROM $table") or mysql_die();
$primary = "";
while ($row = mysql_fetch_array($result))
if ($row["Key_name"] == "PRIMARY")
$primary .= "$row[Column_name], ";
$result = mysql_db_query($db, "SHOW FIELDS FROM $table");
if (!$result) {
mysql_die();
}
else {
echo "<select name=field$num>n";
while ($row= mysql_fetch_array($result)) {
$selected = ($selected_field == $row["Field"]) ? "selected" : "";
echo "<option value=" . $row["Field"] . " $selected>" .
$row["Field"] . "</option>n";
}
echo "</select>nn";
}
}
function show_table($db,$selected_table) {
$tables = mysql_list_tables($db);
$num_tables = @mysql_numrows($tables);
if ($num_tables == 0) {
echo "no table yet";
}
else {
$i = 0;
echo "<select name=table>n";
while ($i < $num_tables) {
$table = mysql_tablename($tables, $i);
$selected = ($selected_table == $table) ? "selected" : "";
echo "<option value=$table $selected>$table</option>n";
$i++;
}
echo "</select>nn";
}
}
if ($submit) {
if(!empty($csv_file) && $csv_file != "none") {
//$csv_file = stripslashes($csv_file);
$fp = fopen($csv_file, "r");
// show first line of the csv file to select dababase table and its fields
echo "<form method=post action=$PHP_SELF>";
$csv_data = fgetcsv($fp, 2000, "$terminated");
$num = count($csv_data);
for ( $c=0; $c<$num; $c++ ) {
$field_name[$c] = $csv_data[$c];
echo $field_name[$c] . " n";
$table_field_name = "field$c";
show_field($db,$table,$c,$$table_field_name);
echo "<br>";
}
// copy the tmp file for next use
$dest = "/tmp/csv_file.csv";
copy($csv_file,$dest);
echo "<input type=hidden name=csv_file value=$dest>n" .
"<input type=hidden name=table value=$table>n" .
"<input type=hidden name=terminated value=$terminated>n" .
"<input type=submit name=submit value=ok></form><p>n";
// when click 'ok' button ,start insert data
if ($submit == "ok") {
$NO = 1;
while ($csv_data = fgetcsv($fp, 2000, "$terminated")) {
//$num = count($csv_data);
for ( $c=0; $c<$num; $c++ ) {
$table_field_name = "field$c";
$first_3 = substr($$table_field_name, 0, 3);
$first_2 = substr($$table_field_name, 0, 2);
$val_tmp = ($first_3 == "fid" || $first_3 == "int"
|| $first_2 == "id") ?
$csv_data[$c] : "'" . $csv_data[$c] . "'";
$val .= $val_tmp . ",";
$var .= $$table_field_name . ",";
}
$val = substr($val, 0, -1);
$var = substr($var, 0, -1);
$query = "INSERT INTO $table ($var) VALUES ($val)";
$val = "";
$var = "";
$q->query($query);
echo "NO. $NO $query<p>";
$NO++;
}
fclose($fp);
}
}
}
?>
[3]PHP中一个控制字符串输出的函数
来源: 互联网 发布时间: 2013-11-30
// php 中 一个控制字符串输出的函数(中英文),每行显示多少字数,避免英文的影响
// $str 字符串
// $len 每行显示的字数(汉字×2)
function rep($str,$len)
{
$strlen=strlen($str);
$i=0;
$finstr="";
$pos=0;
while($i<$strlen)
{
$s1=substr($str,$i,1);
$s2=ord($s1);
if($s2>0xa0){
$finstr.=substr($str,$i,2);
$pos+=2;
$i+=2;
}else{
switch($s2){
case 13:
$finstr.="<BR>";
$pos=0;
break;
case 10:
$pos=0;
break;
case 32;
$finstr.=" ";
$pos++;
break;
default:
$finstr.=htmlspecialchars($s1);
$pos++;
break;
}
$i++;
} //if
if($pos>=$len){
$finstr.="<BR>";
$pos=0;
}
} //while
return $finstr;
}
// $str 字符串
// $len 每行显示的字数(汉字×2)
function rep($str,$len)
{
$strlen=strlen($str);
$i=0;
$finstr="";
$pos=0;
while($i<$strlen)
{
$s1=substr($str,$i,1);
$s2=ord($s1);
if($s2>0xa0){
$finstr.=substr($str,$i,2);
$pos+=2;
$i+=2;
}else{
switch($s2){
case 13:
$finstr.="<BR>";
$pos=0;
break;
case 10:
$pos=0;
break;
case 32;
$finstr.=" ";
$pos++;
break;
default:
$finstr.=htmlspecialchars($s1);
$pos++;
break;
}
$i++;
} //if
if($pos>=$len){
$finstr.="<BR>";
$pos=0;
}
} //while
return $finstr;
}
最新技术文章: