首页 > PHP教程

php 用户注册与登陆程序

php 用户注册与登陆程序
 function islogin_xzy()
 {
  if(!isset($_SESSION['user'])){
   $json['status']=1;
  }else{
   $ssess_=db("session as s");
   $where="s.session_id='".Session_id()."' and u.uid is not null";
   if($user=$ssess_->join("`user` as u on u.uid=s.uid")->field("u.*,s.session_id,s.uid")->where($where)->find()){
    $json['status']=0;
    $json['data']=$user;
   }else{
    $json['status']=1;
   }
  }
  echo json_encode($json);
 }

阅读全文

获取用户IP地址与判断真实IP

获取用户IP地址与判断真实IP
function getIp() {
    if($_SERVER['HTTP_CLIENT_IP'])
    {
        return $_SERVER['HTTP_CLIENT_IP'];
    } elseif ($_SERVER['HTTP_X_FORWARDED_FOR']) {
        return $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        return $_SERVER['REMOTE_ADDR'];
    }
}

阅读全文

php 分页类函数

php 分页类函数
function getPageBar($count = 0)
{
    $bad_link_color = "#C0C0C0";
   
    $page["url"]           = eregi_replace("&page=[^&]+","",basename($_SERVER[SCRIPT_NAME])."?".$_SERVER[QUERY_STRING]);
   
    $page["result_count"]  = (string) $count;
    $page["this_page"]     = (empty($_GET["page"]))?"1":$_GET["page"];
    $page["this_page"]     = ($page["result_count"] == 0)?"0":$page["this_page"];

阅读全文

php从数据库提取二进制图片

<?php
        $conn=@mysql_connect("localhost","root","123") or die("服务器连接错误!"); //链接数据库
        @mysql_select_db("upload",$conn) or die("未发现数据库!");
    $query="select * from upfile where ftag=$fn";
    $result=mysql_query($query);
    if(!$result) die("error: mysql query");
    $num=mysql_num_rows($result);
    if($num<1) die("error: no this recorder");    
    $data = mysql_result($result,0,"picture");
    header("Content-type: image/JPEG",true);
    echo $data;    
?>

阅读全文

php采集入门教程,教你如何写采集

php采集入门教程,教你如何写采集

我们第一步是采集所有的连接,我们这个可不是简单的采集一篇文章哦,我们要做的是采集整本书,并且保存到一个文本,因为现在MP3普及了,都可以看电子书了。
一本书要怎么保存呢,当然是要用书名保存便于查找拉,我们先来采集这本书的标题,
先来看一下原形:
<meta name="description" content="诛仙(二),后金庸武侠圣经:诛仙2">
规律是:
<meta name="description" content="标题">
我们来写一下正则表达式吧,不要告诉我不会,不会就来湖南拉,嘿嘿很多大鸟的。
正则表达式:
<meta name="description" content="(.*?)">
下面开始开工拉!我们首先要获得资源,这里需要用到一个函数:
file_get_contents()
介绍:
主要功能:将整个文件读入一个字符串
  原形是:string file_get_contents
( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )

阅读全文

php smtp邮件群发程序源代码


<?php
/**
*通过phpmailer发送qq邮件
*@author ray
*@since 2009-08-07
*/
define('__DEBUG__', false);
define('__PSW_FILE__', dirname(__FILE__) . '/smtp.dat');
define('SLEEPING_EMAIL', dirname(__FILE__) . "/sleepMail.dat");//休眠的email
define('SLEEPING_TIME', 1800);//休眠多长时间,以秒为单位
define('FILE_APPEND', 1);
if (!function_exists('file_put_contents')) {
    function file_put_contents($n, $d, $flag = false) {
        $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
        $f = @fopen($n, $mode);
        if ($f === false) {
            return 0;
        } else {
            if (is_array($d)) $d = implode($d);
            $bytesWritten = fwrite($f, $d);
            fclose($f);
            return $bytesWritten;
        }
    }
}
$errorNo = 0;
$errorMsg = '';
$currTime = time();
$unuseMails = array();
//收件人和邮件标题和邮件内容
$to = isset($argv[1]) ? $argv[1] : "" ;
$subject = isset($argv[2]) ? $argv[2] : "";
$mailFile = isset($argv[3]) ? $argv[3] : "" ;
if (__DEBUG__) {
    echo "
file:$mailFile to:$to subject:$subjectrn";
}
if (empty($mailFile) || empty($to) || empty($subject)) {
    $errorNo = 1;
    $errorMsg = "参数不全";
}
//加载不可用的email列表
if (!$errorNo) {
    if (file_exists(SLEEPING_EMAIL)) {
        $sleepMails = file(SLEEPING_EMAIL);
        if (!empty($sleepMails)) {
       
            foreach($sleepMails as $sleepMail) {
                //解析
                if (false !== strpos($sleepMail, '|')) {
                    $tmp = explode('|', $sleepMail);
                    if (isset($tmp[0]) && isset($tmp[1])) {
                        $mail = trim($tmp[0]);
                        $time = trim($tmp[1]);
                       
                        //是否可用
                        if ( ($currTime - $time )< SLEEPING_TIME) {
                            $unuseMails[] = $mail;
                        }
                    }
                }
            }
        }
    }
}
if (!$errorNo) {
    //随机加载smtp服务器和smtp用户名和密码
    $info = file(__PSW_FILE__);
    $len = count($info);
   
    do {
        $rnd = mt_rand(0, $len - 1);
        $line = isset($info[$rnd]) ? $info[$rnd] : "";
       
        if (false !== strpos($line, '|')) {
       
            $tmp = explode('|', $line);
            if (isset($tmp[0]) && isset($tmp[1]) && isset($tmp[2])) {
               
                $smtpServer = trim($tmp[0]);
                $fromMail = trim($tmp[1]);
                $psw = trim($tmp[2]);
                $smtpUserName = substr($fromMail, 0, strrpos($fromMail, '@'));
            }
        }
    }while (in_array($fromMail, $unuseMails));//如果在不可用的列表中,在次加载
   
    if (!isset($smtpServer) || !isset($fromMail) || !isset($psw)) {
        $errorNo = 2;
        $errorMsg = "没找到发件人QQ信箱和密码";
    }
}
if (!$errorNo && __DEBUG__) {
    echo "smtp:$smtpServer from:$fromMail psw:$psw user:$smtpUserNamern";
}
if (!$errorNo) {
    //通过phpmailer连接smtp服务器发信
    require(dirname(__FILE__) . "/phpmailer/class.phpmailer.php");
    require(dirname(__FILE__) . "/phpmailer/class.smtp.php");
    $mail = new PHPMailer();
   
    $body = $mail->getFile($mailFile);
    $body = eregi_replace("[]",'',$body);
   
    //charset
    $mail->CharSet = "GB2312";
   
    //$mail->SMTPDebug = 2;//用于显示具体的smtp错误
   
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    if ("smtp.qq.com" == trim($smtpServer)) {
        $mail->Username = $fromMail;
    } else {
        $mail->Username = $smtpUserName;
    }
    $mail->Password = $psw;
    $mail->Host = $smtpServer;
   
    $mail->From = $fromMail;
    $mail->FromName = "晴天网络";
   
    $mail->IsHTML(true);
   
    $mail->AddAddress($to);
    $mail->Subject = $subject;
    $mail->Body = $body;
   
    if (!$mail->Send()) {
   
       // echo "Message could not be sent. ";
        $errorNo = 3;
        $errorMsg = $mail->ErrorInfo;
    } else {
        echo "
Send to $to success use $fromMailrn";
        exit;
    }
}
if (3 == $errorNo) {
    //记录信息,该信息地址休眠N分钟
    $content = "$fromMail|" . time() . "rn";//email|当前时间戳
    file_put_contents(SLEEPING_EMAIL, $content, FILE_APPEND);
}
echo "
Error No($errorNo) " . $errorMsg . "rn";
exit;
?>

阅读全文