存档
现在php的项目,动不动就smarty。甚至有的朋友做个两三个页面的新闻系统,也要用smarty。今天按捺不做,谢谢我的看法。本文原文地址为:http://www.miaoqiyuan.cn/p/template-thinks,希望转贴的朋友留一个我的链接。
做个新闻系统,不用smarty,10KB以内的代码搞定,如果用smarty后,就要几百KB了。有些人可能会说不用模板,修改的时候不方便,或则需要每篇文章使用不同的模板,直接用php代码,就不好控制了,在这里给我大家分享一套另类的模板方法。
<?php
#init.php
#获取皮肤设置,如果不存在,则调用default.php
$skin = trim($_GET['skin']);
if(!isset($skin) || @$skin==”){
$skin = ’skin/default.php’;
}else{
$skin = ’skin/’.$skin.’.php’;
if(!is_file($skin)){
$skin = ’skin/default.php’;
}
}
?>
数据处理文件
<?php
[...]
联网下,一分钟安装LAMP环境。
Ubuntu下安装 apache2 + php5 + mysql 1. 安装运行环境
sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt-get install php5-common
sudo apt-get install php5-gd
sudo apt-get install php5-mysql
sudo apt-get install libapache2-mod-php5
apache2默认的 sites路径在
/var/www/sites
哈哈,很快把
2. 配置php5
sudo gedit /etc/php5/apache2/php.ini
修改允许最大使用内存,查找
memory_limit = 8M
修改为
memory_limit = 32M
修改允许最大上传尺寸,查找
upload_max_filesize = 2M
修改为
upload_max_filesize = 8M
允许 mysql 和 gd 模块,检查文件最后是否包含下面的代码,如果没有添加上。(默认是在配置文件最后有添加的,检查一下以防万一)
extension=mysql.so
extension=gd.so
保存并关闭文件。
3. 配置 mysql,让它支持其它客户端访问,如果你不需要就不用修改。
sudo gedit /etc/mysql/my.cnf
查找 文件
skip-networking
修改为
#skip-networking
保存并关闭文件。
重 新启动 [...]
最近准备放弃使用许久的vbscript作为处理工作方面问题,而转向PHP。
应该是ASP转向PHP把,怎么是vbscript转向php?这个我要说一下,处理工作方面问题,比如通过API导个数据…用ASP,PHP在IIS中执行肯定不行,写个VBScript脚本,cscript 脚本名 让他执行吧,别的不用关了。所以用脚本处理些数据转换、导入导出还是不错的选择。
VBScript的致命的缺点是不支持引用文件,对HTTP请求方便不是很强,正则、XML处理起来不方面,JSON作为数据载体时就等着傻眼把。这是后用php作为脚本也是一个不错的选择。扯得有点远了,换成了php,数据库还是Access怎么办?这个简单,直接用com创建adodb实例即可。
现在已经创建好了数据库,只填写了部分域名,要通过php到域名查询接口返回whois信息,并存到Access数据库中,Access字段名已对应返回数组中的索引相同。
<?php
set_time_limit(0);
#因为要链接web,使用我前几天写的myhttp类。
include(‘myhttp.clsss.php’);
#API操作,这里直接忽略,里边有个get_domain_info来获取API返回的数据,并处理成数组。
include(‘api.function.php’);
$conn = new COM("Adodb.Connection");
$conn -> open("provider=microsoft.jet.oledb.4.0;data source=D:\myweb\miaoqiyuan.cn\test\php-linkdb\domain.mdb");
$dlist = new COM("ADODB.Recordset");
$rs = new COM("ADODB.Recordset");
$dlist -> open("select [domain],[did] from [domain] where isupdate=0",$conn,1,1);
while(!$dlist -> eof()){
echo "下载域名数据[".$dlist['domain']."].\n";
$d=get_domain_info($dlist['domain']);
$rs -> open("select * from [domain] where did=".$dlist['did'],$conn,3,2);
foreach($rs -> fields as $k => $v){
if($k >= 6){
$myvalue = [...]
最近一直在写淘宝客的程序,因为网络的原因,file_get_contents经常读取出错,想到了比较稳定的方法,使用fsockopen连接API。fsockopen 函数在网上介绍的还是很多的,但是介绍再多,创建http请求仍然是一件比较麻烦的。
fsockopen调用的方法比较繁琐,要使用得到的数据还要去掉http头,所以冒出了写一个通用的类的方法。今天正好是51假日,在家写了这种的一个类。
<?php
/*
CatSeven myHttp Vesion 0.1
======CopyRight======
Home:http://www.myw3.cn/myDevise/myHttp/
Design:Miao Qiyuan[miaoqiyuan.cn]
Downloads:http://downloads.myw3.cn/file=myDevise/myHttp/0.1
*/
class myHttp{
public $Method,$URI,$SendDate;
public $HttpServerPort,$HttpServer,$HttpServerIP;
public $Err,$ErrStr;
public $timeout;
public $responseText;
public function __construct($uri=’/',$method=’get’,$query=”,$server=’localhost’,$port=’80′,$serverip=”,$timeout=30){
$this->URI=$uri;
$this->Method=$method;
$this->SendDate=$query;
$this->HttpServer=$server;
$this->HttpServerPort=$port;
$this->HttpServerIP=$serverip;
if(is_numeric($timeout))$this->timeout=$timeout;
}
public function send(){
$this->Method=strtoupper($this->Method);
if($this->HttpServerIP=="")$this->HttpServerIP = $this->HttpServer;
if($this->Method=="GET" && strstr($this->URI,"?")==0)$this->URI=$this->URI."?".$this->SendDate;
$sock = fsockopen($this->HttpServerIP,$this->HttpServerPort,$errno,$errstr,$this->timeout);
if(!$sock){
$this->ErrStr=$errstr;
$this->Err=$errno;
die("无法打开".$this->HttpServerIP.":".$this->HttpServerPort);
}
fwrite($sock, $this->Method." ".$this->URI." HTTP/1.0\r\n");
fwrite($sock, "Host: ".$this->HttpServer."\r\n");
if($this->Method=="POST"){
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: ".strlen($this->SendDate) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, $this->SendDate."\r\n");
fwrite($sock, "\r\n");
fwrite($sock, "Referer: http://www.myw3.cn/myDevise/myHttp/");
}
fwrite($sock, "Connection: Close\r\n\r\n");
$headers = "";
while ($str = trim(fgets($sock,4096)))
$headers .= "$str\n";
$body = [...]
当PHP.ini设置register_globals = On是,通过GET提交的数据可以直接使用表单名调用GET提交的数据。asp就不可以,我想到了asp的execute,也谢了一个脚本,还能过滤SQL注入字符串
<%
Dim myRegExp
set myRegExp=New RegExp
myRegExp.Pattern = "[^a-z0-9_]"
myRegExp.Global=True
for each Req in Request.Querystring
ReqV=Request.Querystring(Req)
if trim(ReqV)<>"" then
ReqV=replace(ReqV,"""","""""")
Req=myRegExp.Replace(Req,"")
Execute(Req&"="""&ReqV&"""")
end if
next
response.write a
%>
调用很简单。比如GET提交/get_Test.asp?a=111&b=222
则直接可以使用Response.write a,输出结果为111。简单吧~
再次感谢小秦(Q48080163)提出的bug
在织梦的论坛上看到好几篇关于自定义dedeeims的路径,不让dedeeims产品页生成静态之类的求助信息。确实,dedeeims的产品路径还带有日期,如果动态的路径,整站到再/plus/下,感觉特别不爽,今天我就给修改一下。
首先让我们感觉不爽的就是/plus/list.php?tid=这种路径作为频道(栏目,分类页),感觉特别不爽,我们就先从它下手。打开include\channelunit.func.php,找到//$reurl = $GLOBALS['cfg_phpurl'].”/list.php?tid=”.$typeid;,直接修改成$reurl = “/class.php?id=”.$typeid;这样,所有的分类页就变成了/class.php?id=…的形式了。在根目录建立一个class.php,内容如下:
< ?php
$tid=$_GET['id'];
require_once(‘plus/list.php’);
?>
很简单吧,下面修改产品展示页路径为product.php,阅读新闻页为news.php。
找到include\channelunit.func.php,function GetFileUrl($aid,$typeid,$timetag,$title,$ismake=0,$rank=0,$namerule=”,$typedir=”, $filename=”),假设产品分类为4,10,新闻分类为3,9。直接添加上如下代码:
< ?php
if($typeid==4||$typeid==10)
return ‘/product.php?product_id=’.$aid;
elseif($typeid==3||$typeid==9)
return ‘/news.php?id=’.$aid;
else
return ‘/plus/view.php?aid=’.$aid;
?>
其他情况就是默认路径了。当然也可以改成/view.php?aid=…
news.php
<?php
$aid=$_GET['id'];
require_once(‘plus/view.php’);
?>
product.php
<?php
$aid=$_GET['product_id'];
require_once(‘plus/view.php’);
?>
现在前台基本就没有问题了,后台预览文件的时候,可能会出现错误,修改admin\archives_do.php代码如下:
function viewArchives()
–>>…
if(strpos($arcurl,’?')==-1)
echo "$lt;script language=’javascript’>location.href=’$arcurl"."?".time()."’;$lt;/script>";
else
echo "$lt;script language=’javascript’>location.href=’$arcurl"."&tme=".time()."’;$lt;/script>";
exit();