apache rewrite 讲解
ServerAdmin host@discuz.com
DocumentRoot D:/www
ServerName www.xiaojia.com
ServerAlias xiaojia.com xiaojia.net
ErrorLog D:/www/logs/xiaojia.com-error_log
CustomLog D:/www/logs/xiaojia.com-access_log%Y%m%d combined
# Alias /upimg "/home/www/wwwroot/phpchina.cn/upimg/"
# Alias /wiki "/home/www/wwwroot/phpchina.cn/wiki/"
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteCond %{HTTP_HOST} !111cn.net [OR]
# RewriteCond %{HTTP_HOST} !www.111cn.net
# RewriteRule ^(.*)$ http://www.111cn.net$1 [R=301,L]
RewriteRule ^(.*)/archiver/([a-z0-9\-]+\.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3
</IfModule>
</VirtualHost>
/************/
config.php
/***********/
<?php
$host = 'localhost'; // 数据库服务器
$user = 'root'; // 数据库用户名
$password = '123456'; // 数据库密码
$db = 'project'; // 数据库名
//打开数据库
$conn = mysql_pconnect ($host,$user,$password);
if(!$db)
{
die('<b>数据库连接失败!</b>');
}
//选择数据库
mysql_select_db ($db);
?>
/*********************/
index.php
/********************/
<html>
<body>
<script type="text/javascript">
function check_form(obj){
if(document.getElementById('post_name').value==''){
alert('写一下您的大名吧');
document.getElementById('post_name').focus();
return false;
}
if(document.getElementById('post_body').value==''){
alert('不是来捣乱的吧,写一下留言内容吧!');
document.getElementById('post_body').focus();
return false;
}
return true;
}
</script>
<form action="/sent.php" method="post" onSubmit="return check_form(this)">
<table width="100%" border="0">
<tr>
<td align="right">您的大名</td>
<td><input name="post_name" id="post_name" type="text" size="20" maxlength="20"></td>
</tr>
<td align="right">您的发言</td>
<td><textarea name="post_body" id="post_body" rows="10" cols="50">您的发言</textarea></td>
<tr>
<td align="right"> </td>
<td><input type="submit" name="Submit" value="提 交" ></td>
</tr>
</table>
</form></td>
</body>
<html>
<?php
include('get.php')
?>
/***************************/
get.php
/****************************/
[quote]
<?php
include('config.php');
$query = "SELECT * FROM project_post";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) echo "姓名:$row[post_name] </br> 内容: $row[post_body]</br>";
?>
/***************************/
sent.php
/***************************/
<?php
include('config.php');
$post_name=addslashes($_POST['post_name']);
$post_body=addslashes($_POST['post_body']);
$sql = "INSERT INTO project_post (post_name,post_body) VALUES('$post_name','$post_body')";
mysql_query($sql);
header('location:/index.php');
?>
$path=$_SERVER["DOCUMENT_ROOT"];//服务器路径
$i = 0;
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$upload_file=$_FILES['pictures']['tmp_name'][$key];//文件被上传后在服务端储存的临时文件名
$imgtype = strtolower(strrchr($_FILES['pictures']['name'][$key],"."));
$name_1 = strtolower(substr($_FILES["pictures"]["name"][$key],0,2));
$upload_file_name= "lanmayi_".time().$name_1.$imgtype;//以字母及系统时间的秒来做文件名
$store_dir = $path."/up_img/";// 上传文件的储存位置
$file_size_max = 100000000000;// 1M限制文件上传最大容量(bytes)
$accept_overwrite = 0;//是否允许覆盖相同文件
move_uploaded_file($upload_file,$store_dir.$upload_file_name);
$new_img_name = $upload_file_name;
$new_img_type = substr($imgtype,1,3);
$new_img_path = $store_dir;
$suo_name = Makesuo ($new_img_path,$new_img_name,$new_img_type);
$sh_time = date('Y-m-d H:i:s');
$name = $_POST['name'];
$pid = $id;
$sql = "insert into lanmayi_img_show(pid,sh_name,sh_url,sh_suo,sh_time) values (".$pid.",'".$name[$i]."','".$upload_file_name."','".$suo_name."','".$sh_time."')";
$res = mysqli_query($conn,$sql);
$i++;
}
}
//*批量上传结束********************************************************
?>
<script language="javascript">
alert("图片上传成功!")
</script>
<?php
}
if($_POST['fanhui']){
?>
<script language="javascript">
window.location='pro_list.php?id=<?php echo $id?>';
</script>
<?php
}
?>
先看htm文件吧
<html>
<head>
<title><{$title}></title>
<{$xajax_javascript}><{*使smarty支持xajax*}>
</head>
<body>
<form name="check" >
请输入用户名:
<input type="text" name="username" />
<input type="button" name="button" value="检查用户名" />
<div id="result"></div>
</form>
</body>
</html>
php处理代码
<?php
/*****************************************
Title :smarty结合xajax检测用户名简单实例
Author:leehui1983(辉老大)
Finish Date :2006-12-09
*****************************************/
//为避免中文乱码,需要在 xajax.inc.php 需要改一下默认的encoding:define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gbk' )UTF8编码格式文件不需要更改
require_once('./libs/Smarty.class.php');//包含smarty类库
require('./xajax/xajax.inc.php');//包含xajax类库
function checkusername($textvalue){//编写需要的PHP函数
$checkresult=($textvalue=='test' ? '<font color=red>该用户名已经注册</font>' :'<font color=red>可以注册</font>');
$objresponse=new xajaxResponse();//实例化xajaxresponse对象
$objresponse->addassign("result","innerHTML",$checkresult);//指定ID为result的元素中添加内容$checkresult
return $objresponse;//返回结果文本
}
$xajax=new xajax();//实例化xajax对象
$smarty=new Smarty();//实例化smarty对象
$smarty->template_dir = "./templates";//设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->caching = false; //设置缓存方式
/*****************************************************
左右边界符,默认为{},但实际应用当中容易与JavaScript
相冲突,所以建议设成<{}>或其它。
*****************************************************/
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$xajax->registerFunction("checkusername");//注册checkusername函数
$xajax->processRequests();//调用xajax用于接管请求
$smarty->assign('xajax_javascript', $xajax->getJavascript('./xajax/'));//输出JS代码,注意('./xajax/')中参数为xajax.inc.php父目录,在同意目录下可不同填写,否则必须填写
$smarty->assign('title','smarty结合xajax检测用户名简单实例');//替换模板内容
$smarty->display('index.tpl');//显示模板内容
?>
<html>
<head>
<title>filemanage</title>
</head>
<body>
<center>
<p><h2>文件管理</h2></p><br>
<table border=1><tr size=18>
<td>文件ID</td><td>文件名称</td><td>文件大小</td><td>上传时间</td><td>下载</td><td>删除</td></tr>
<?php
include("conn.php");
//echo '<table border=1>';
$rs=$db->query("select * from filem order by f_id DESC");
$i=1;
while($row = $rs->fetch_assoc())
{
$size=$row['f_size']/1024;
echo "<tr><td>".$i++."</td><td>".$row['f_name']."</td><td>".number_format($size, 2, '.', '')."KB</td><td>".$row['f_date']."</td><td><a href=".$row['f_url']." target=_blank>下载</a></td><td><a href=del.php?id=".$row['f_id'].">删除</a></td></tr>";
}
echo '</table>';
unset($rs);
$db->close();
?>
</center>
<br><br><hr><br>
<b><h2>uploadfile</h2></b>
<br>
<form enctype="multipart/form-data" action="" method="post">
选择上传文件:<br><input name="userfile" type="file"><br>
<input type="submit" value="发送">
</form>
<?php
if(!$_FILES["userfile"]["name"]) exit;
//echo $_FILES['userfile']['type'];
if ($_FILES['userfile']['error'] > 0)
{
echo 'Problem: ';
switch ($_FILES['userfile']['error'])
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo '不能超过800M'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
else
{ //检查上传文件是否在允许上传的类型
$tp = array("gif","jpeg","png","txt","doc","rar","zip","xls","bmp","wmv","mp3","flv","rmvb","avi");
if (!in_array(strtolower(substr(strrchr($_FILES['userfile']['name'], '.'),1)), $tp))
{
echo '文件类型错误,请重新选择文件!<br>只允许rar,zip,jpg,gif,txt,png,bmp,xls类型的文件';
exit;
}
$path="./file/"; //上传路径
if(file_exists($path.$_FILES['userfile']['name'])) //判断文件是否存在
{
echo '文件已存在,请更改后重新上传!';
exit;
}
if($_FILES["userfile"]["name"])
{
$file1=$_FILES["userfile"]["name"];
$file2 = $path.$file1;
$flag=1;
}
if($flag)
$result=move_uploaded_file($_FILES["userfile"]["tmp_name"],$file2);
//特别注意这里传递给move_uploaded_file的第一个参数为上传到服务器上的临时文件
if($result)
{
$time=date("Y-m-d");
// $url=$patch.$name;
$size=$_FILES["userfile"]["size"];
include("conn.php");
$rs=$db->query("insert into filem(f_name,f_url,f_date,f_size) values('$file1','$file2','$time','$size')");
// $rs=$db->query($sql);
echo "<script language='javascript'>location='index.php';</script>";
}
unset($rs);
$db->close();
}
?>
</body>
</html>
相关文章
从PHP $_SERVER相关参数判断是否支持Rewrite模块
如果是http://www.jb51.net/p1141.html形式的URL,可通过$_SERVER['REQUEST_URI']和$_SERVER['QUERY_STRING']值的区别来分析,最主要是如果页面是通过重定向会产生$_SERVER['REDIRECT_QUERY_STRING']和$_SERVER['REDIREC...2013-10-04Apache启动报错No space left on device: AH00023该怎么解决
Apache启动报错No space left on device: AH00023错误可能是进程导致了,虽然小编不知道什么原因但网上提供的解决办法确实是可以解决我们的问题,下面来看看。对于这类错误是因为linux系统的ipc信号量造成的,apache启动时...2015-10-21- 本文我们将分享apache配置黑名单和白名单,apache层的账户权限控制,以及apache黑名单白名单过滤功能,apache rewrite规则实现白名单。 apache配置黑名单和白名单的两...2016-09-14
- 今天在用百度工具检测时发,发现有个提示如下 原来可以开启gzip啊,因为我的是apache所以和iis不同,经过网站搜索开启方法如下 一,找到你的httpd.conf文件,打开找到如下 ...2016-01-28
解决PHPstudy Apache无法启动的问题【亲测有效】
这篇文章主要介绍了PHPstudy Apache无法启动的问题及解决方法【亲测有效】,本文给大家总结了三种方法供大家参考,需要的朋友可以参考下...2020-10-30apache http server遇到了一个问题,需要关闭
重装系统后,重新安装了xamp,最近启动的时候经常报apache http server遇到了一个问题,需要关闭,显示如图: 解决方法:查看szModName报错的模块,然后把PHP安装目录下对应的模块...2016-01-28Windows Server 2016 上配置 APACHE+SSL+PHP+perl的教程详解
Windows Server 2016 上配置 APACHE+SSL+PHP+perl怎么配置?小编推荐了一篇介绍Windows Server 2016 上配置 APACHE+SSL+PHP+perl的教程,有需要的同学快来看看吧! ...2017-07-06nginx+apache+mysql+php+memcached+squid搭建集群web环境
当前,LAMP开发模式是WEB开发的首选,如何搭建一个高效、可靠、稳定的WEB服务器一直是个热门主题,本文就是这个主题的一次尝试。...2016-01-27- 这篇文章主要介绍了隐藏Nginx或Apache以及PHP的版本号的方法,主要用来防止针对性的漏洞攻击,需要的朋友可以参考下...2016-01-05
- 默认情况下,apache安装完以后,是不允许被cache的。如果外接了cache或squid服务器要求进行web加速的话,就需要在htttpd.conf里进行设置,当然前提是在安装apache的时候要激活mod_c...2016-01-28
- Order A, B (其中,A和B均可以代表allow或者deny,以下conlist表示控制列表) A from conlist1 B from conlist2 那么最终访问控制的结果为:(以(A)表示A的控制范围,) (A)= (conli...2016-01-28
- Satisfy directive Syntax: Satisfy 'any' or 'all' Default: Satisfy all Context: directory, .htaccess Status: core Compatibility: Satisfy is only available...2016-11-25
- 任何二级域名,均跳转到www下。 本地测试站点:www.111cn.net,下面是apache里的配置: 代码如下 复制代码 <VirtualHost *> <Directory "D:/webroot/myp...2016-01-28
- 下载下列文件至/usr/local/src/ apache(Unix平台最流行的WEB服务器平台)2.tar.gz MySQL(和PHP搭配之最佳组合)-5.0.22.tar.gz php(做为现在的主流开发语言)-5.1.2...2016-11-25
以动态模块的方式安装apache2.0.44+PHP4.3.0
经过一天的努力,终于装完了apache2.0.44+PHP4.3.0呵呵, 不禁佩服自己的愚蠢 :( 以前安装都是用php静态模块的方式,似乎在apache2以上的版本上行不通(猜测而已:)) 安装过程简...2016-11-25- AuthName directive Syntax: AuthName auth-domain Context: directory, .htaccess Override: AuthConfig Status: core This directive sets the name of the author...2016-11-25
- 每个网管最黑暗的时候莫过于服务器被攻击后的束手无策,其实服务器遭受攻击后,服务器的记录文件详细地记录了黑客活动的蛛丝马迹。...2016-01-27
ThinkPhP+Apache+PHPstorm整合框架流程图解
这篇文章主要介绍了ThinkPhP+Apache+PHPstorm整合框架流程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-23- 编辑.htaccess的方法。 注意:在设置301重定向之前务必备份相应目录下的.htaccess文件。 1.重定向111cn.net到www.111cn.net 这种重定向旨在使域名唯一,是网站seo教程必...2016-01-28
- 下载模块: http://www.nowhere-land.org/prog ... st_limit-0.4.tar.gz 官方网址: http://www.nowhere-land.org/programs/mod_vhost_limit/ 安装: apxs -c mod_vhost_...2016-01-28