【PHP5对Mysql5的任意数据库表的管理代码示例(二)】教程文章相关的互联网学习教程文章

php购物车的简单实现代码与示例

session_start(); $conn=mysql_connect("localhost","root","admin"); mysql_select_db("songyu"); //检查数组元素出现次数 function check_count($array,$element) { $times=0; for($i=0;$i { if($element==$array[$i]) { $times++; } } return $times; }if(isset($_GET["p_id"])){ $p_id=$_GET["p_id"];}$total_price=0; array_push($_SESSION["cart"], $p_id); $cart=$_SESSION["cart"]; echo "your cart:"; $ne...

php复制目录及所有文件的代码示例

/** * 复制目录函数 * @param $src 源目录 * @param $dst 目标目录*/function recurse_copy($src,$dst) { $dir = opendir($src); @mkdir($dst); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) { recurse_copy($src . '/' . $file,$dst . '/' . $file); } else { copy($src . '/' . $file,$dst . ...

php计算两个日期间隔的年、月、周、日数的代码示例

/*** 计算两个日期间隔的年、月、周、日数* edit bbs.it-home.org*/function format($a,$b){//检查两个日期大小,默认前小后大,如果前大后小则交换位置以保证前小后大if(strtotime($a)>strtotime($b)) list($a,$b)=array($b,$a);$start = strtotime($a);$stop = strtotime($b);$extend = ($stop-$start)/86400;$result['extends'] = $extend;if($extend$result['daily'] = $extend;}elseif($extendif($stop==strtotime($a.'+1 mon...

phpreadfile函数下载文件并判断权限的代码示例

/*** header与readfile函数应用举例* 下载文件 判断权限* edit bbs.it-home.org*/ $file = get_file_address();// 文件的真实地址(支持url,不过不建议用url) if (file_exists($file)) {header('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename='.basename($file));header('Content-Transfer-Encoding: binary');header('Expires: 0'...

phpmysql实现用户登录功能的代码示例

本文介绍下,php与mysql结合,实现用户登录功能的一段代码,适合初学的朋友参考,用来研究php用户登录的实现方法,还是有点借鉴意义的。接着上次的php mysql添加用户的功能代码,今天来学习下php实现用户登录与注销的功能,通过跟踪session会话来保存用户的登陆状态。 1,登录页面 login.php用户登录_bbs.it-home.org代码说明: 很简单的一个登陆界面,POST数据到loginchk.php页面,以进行用户验证。 2,登录检测页面 loginchk.php...

php实现用户注册的代码示例

本文介绍下,php实现的用户注册信息检测与入库的例子,有需要的朋友参考下吧。代码如下:query('set names gb2312'); if(empty($conn)) {die("数据库连接失败"); } $UserName=$_POST['username']; $pwd=$_POST['password']; $email=$_POST['email']; $sex=$_POST['sex']; $time=time(); $code=strtolower($_POST["code"]); $str="select * from users where username='".$username."'";$result1=$conn->query($str);$row=$result1-...

php记录搜索引擎关键词的代码示例

本文介绍下,用php实现记录搜索引擎关键词的一段代码,作为初学者的入门参考,还是不错的。用php实现记录搜索引擎搜索关键词,代码如下:'word', 'google.com'=>'q', 'sina.com.cn'=>'word', 'sohu.com'=>'word', 'msn.com'=>'q', 'bing.com'=>'q', '163.com'=>'q', 'yahoo.com'=>'p' ); $keyword=''; $sengine=$p['host']; foreach($arr_sd_key as $se=>$kwd) { if(strpos($p['host'],$se)!==false) { $keyword=$p...

CodeIgniter上传图片的代码示例

分享一段CodeIgniter上传图片的代码,对于研究CodeIgniter这个php框架的朋友来说,可以作个参考。用CodeIgniter的上传类实现上传图片,测试中遇到一些问题,这里分享下要注意的地方:/*注意,此处是userfile,$this->upload->do_upload(),这里do_upload默认上传文件的表单名为userfile; 当然也可以使用do_upload($filename),此处的$filename一定要和form_upload()里面的字符串一致. */controller控制器代码: function upload() { $...

php创建标签云的代码示例

本文介绍下,用php创建标签云的一段代码,通过自定义的php函数创建标签云效果。有需要的朋友参考下。php 标签云的创建代码一例,如下:$count ) { $size = $minFontSize + ( $count - $minimumCount ) * ( $maxFontSize - $minFontSize ) / $spread; $cloudTags[] = '' . htmlspecialchars( stripslashes( $tag ) ) . ''; } return join( "\n", $cloudTags ) . "\n"; } /*** Sample usage ***/ $arr = Array('Actionscript' => 35,...

php基准时间的代码示例

本文介绍下,在php中用于处理基准时间的一段代码,有需要的朋友,参考下吧。Here is a little example of how to benchmark or time something with php 这里有一段php代码,教大家如何去处理基准时间。 代码如下:'; }// the end time $time_end = getmicrotime();// subtract the start time from the end time to get the time taken $time = $time_end - $time_start;// echo a little message echo 'Script ran for ' . round...

php用户登录检测的代码示例

本文分享一个简单的php用户登录代码,通过将用户名与密码与存储在数组中的值进行比对,检测是否有效。有需要的朋友可以作个参考。首先,将用户名与密码存储在数组中,当有用户登录时,从数组中取值参与检测,以判断用户名与密码是否有效。 登录与检测在同一个文件LoginFormAction中,代码:"pass1", "name2" =>"pass2");if ($password == $passwords[$username]){setcookie("username", $username, time()+1200);echo "登录成功....

提取html标签的php代码示例

提取html标签的php代码示例 <?php /** * 函数: tags * 功能: 从文件中提取html标签 * * 入口: * $filename 文件名 * $tag 标签名 * 返回: * 数组,每项为: * tagName String * Text String * Attrs Array * * 示例: * print_r(tags("test1.htm","a")); * print_r("http://localhost/index.htm","img"); * */</p> <p>function tags($filename,$tag) { $buffer = join("",file($filename)); $buffer = eregi_replace("\r\n","",$buffe...

php数组去重的函数代码示例

/*** 去除数组中重复值的函数* by bbs.it-home.org*/function array_assoc_unique($arr, $key) { $tmp_arr = array(); foreach($arr as $k => $v) { if(in_array($v[$key], $tmp_arr)) { unset($arr[$k]); } else { $tmp_arr[] = $v[$key]; } } sort($arr); return $arr; } //调用示例 去除数据中重复值$aa = array( array('id' => 123, 'name' => '脚本学堂'), ...

php防止sql注入的代码示例

<?phpFunction inject_check($sql_str) { return eregi(select|insert|and|or|update|delete|\|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile, $sql_str);}if (inject_check($_SERVER[QUERY_STRING])==1 or inject_check(file_get_contents("php://input"))==1){ //echo "警告 非法访问!"; header("Location: Error.php");}例2,批量过滤post,get敏感数据<?php$_GET = stripslashes_array($_GET);$_POST = stripslashes_arra...

PHP防CC攻击代码示例

<?php$P_S_T = $t_array[0] + $t_array[1]; $timestamp = time();session_start(); $ll_nowtime = $timestamp ; if (session_is_registered(ll_lasttime)){ $ll_lasttime = $_SESSION[ll_lasttime]; $ll_times = $_SESSION[ll_times] + 1; $_SESSION[ll_times] = $ll_times; }else{ $ll_lasttime = $ll_nowtime; $ll_times = 1; $_SESSION[ll_times] = $ll_times; $_SESSION[ll_lasttime] = $ll_lasttime; } if (($ll_nowtime - $l...

MYSQL5 - 相关标签
PHP5 - 相关标签