大师网-带你快速走向大师之路 解决你在学习过程中的疑惑,带你快速进入大师之门。节省时间,提升效率

PHP笔记

表单

//检查表单是否已提交
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        echo "post";
    }


//post接受数据
$name = $_POST['name'];

数据库

<?php
    //----------------------------------------------------------------------------
    //                                              数据库连接
    //----------------------------------------------------------------------------
    //数据服务器
    $mysql_server_name  =   "192.168.1.100";        //数据库服务器名称
    $mysql_username     =   "root";             // 连接数据库用户名
    $mysql_password     =   "123456";           // 连接数据库密码
    $mysql_database     =   "";         // 数据库的名
    // 连接到数据库
    mysql_connect($mysql_server_name, $mysql_username, $mysql_password) or die("db error");
    mysql_select_db($mysql_database);
    mysql_query("SET NAMES 'UTF8'");
?>

session

session_start();//session开始

$_SESSION['name'] = $name;//设置session的值

//判断session存储的name是否存在
if(!isset($_SESSION['name'])){
        exit();
    }

//退出登录用到
      $_SESSION = array();
    //清楚客户端sessionid
    if(isset($_COOKIE[session_name()]))
    {
      setCookie(session_name(),'',time()-3600,'/');
    }
    //彻底销毁session
    session_destroy();
    echo "<script>window.location.href='index.php';</script>";

数据库操作1

$sql = "SELECT * FROM `wd_module` where parent_module ='".$row["id"]."' order by id";
$req = mysql_query($sql);
while ($ro = mysql_fetch_array($req))
  {
    //<!-- 循环二级模块 -->
    echo "<tr target=\"id\" rel=\"".$ro['id']."\">
            <td>|------- &nbsp;".$ro['name']."</td>
            <td>".$ro['url']."</td>
            <td>".$ro['remark']."</td>
            <td>".$ro['create_time']."</td>
            <td>".empty($ro['modify_time']? $ro['create_time']:$ro['modify_time'])."</td>
          </tr>";
  }

数据库操作2

<?php
    $name = $_SESSION['name'];
    $sql = "select * from wd_user where login_id='$name'";
    $request = mysql_fetch_assoc(mysql_query($sql));
        echo $request["login_id"];
?>

.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>