setcookie函数的作用域问题(0 位领导批示)

在不同目录下的文件.不能访问各自设置的cookie

查了一下手册.setcookie函数有一个path参数.可以设置本地cookie的作用域

解释如下:

The path on the server in which the cookie will be available on. If set to ‘/’, the cookie will be available within the entire domain . If set to ‘/foo/’, the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

另一个参数domain
则是设置网络上cookie的作用域.

解释如下:

The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you’d set it to ‘.example.com’. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details.

示例:

  1. $setcookday = 30;//设置cookie有效期
  2. setcookie('uname', '银子', time() + ($setcookday * 24 * 60 * 60),'/','qqdang.net'); //分别为cookie名称.cookie值.cookie有效时间.cookie本地作用域.cookie网络作用域

Discuz的install文件核心函数(2 位领导批示)

可以将自己写的程序做一个install.php.
Discuz的install文件中的核心函数,相当精简..

  1. <?php
  2. require("connect.inc.php");
  3. $sqlfile = 'test.sql';//sql文件
  4.  
  5. $fp = fopen($sqlfile, 'rb');
  6. $filesize=filesize($sqlfile);
  7. $sql = fread($fp, $filesize);
  8. fclose($fp);
  9. runquery($sql);
  10.  
  11. function runquery($sql) {
  12.     global $lang, $dbcharset, $tablepre, $db;
  13.  
  14.     $sql = str_replace("\r", "\n", str_replace(' cdb_', ' '.$tablepre, $sql));
  15.     $ret = array();
  16.     $num = 0;
  17.     foreach(explode(";\n", trim($sql)) as $query) {
  18.         $queries = explode("\n", trim($query));
  19.         foreach($queries as $query) {
  20.             $ret[$num] .= $query[0] == '#' || $query[0].$query[1] == '--' ? '' : $query;
  21.         }
  22.         $num++;
  23.     }
  24.     unset($sql);
  25.  
  26.     foreach($ret as $query) {
  27.         $query = trim($query);
  28.         if($query) {
  29.             if(substr($query, 0, 12) == 'CREATE TABLE') {
  30.                 $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  31.                 echo $lang['create_table'].' '.$name.' ... <font color="#0000EE">'.$lang['succeed'].'</font><br>';
  32.                 mysql_query(createtable($query, $dbcharset));
  33.             } else {
  34.                 mysql_query($query);
  35.             }
  36.         }
  37.     }
  38. }
  39. ?>

(备忘)MySQL字段类型(2 位领导批示)

MySQL支持大量的列类型,它可以被分为3类:数字类型、日期和时间类型以及字符串(字符)类型。本节首先给出可用类型的一个概述,并且总结每个列类型的存储需求,然后提供每个类中的类型性质的更详细的描述。概述有意简化,更详细的说明应该考虑到有关特定列类型的附加信息,例如你能为其指定值的允许格式。

由MySQL支持的列类型列在下面。下列代码字母用于描述中:

 

M
指出最大的显示尺寸。最大的合法的显示尺寸是 255 。
D
适用于浮点类型并且指出跟随在十进制小数点后的数码的数量。最大可能的值是30,但是应该不大于M-2。
方括号(“[”和“]”)指出可选的类型修饰符的部分。

注意,如果你指定一个了为ZEROFILL,MySQL将为该列自动地增加UNSIGNED属性。

全文阅读 »

Navicat for MySql(4 位领导批示)

Navicat 头儿推荐给我的MySql可视化开发管理工具

Navicat最大的好处就是数据同步与数据的转移..相比来说phpmyadmin就太过不专业了.

主要功能:
-表单检视
-虚拟群组
-自动完码
-排程工作结果自动传送电子邮件
-查询、 检视及事件自动完码
-报告可汇出成各种格式,PDF, Excel, HTML 等
-超时自动重新连接到SQL服务器
-数据和结构同步
-导出注册文件以传送到另外的计算机
-新查询创建器–为不同的数据库创建查询
-查询参数
-SQL控制台
-建立查看
-SSH密钥
-支持所有MySQL版本
-SSH及HTTP隧道
-汇入/汇出数据
-报表设计及建立

软件界面
Navicat for MySql

下载地址: http://www.navicat.com.cn

不过推荐使用英文版,汉化的台湾国语化比较重,用英文还是原汁原味点

UTF-8编码截取中文字符串函数(1 位领导批示)

记录一下,非常好用

/**
* UTF-8 中文切字
*
@param    string    需要切分的字符串
*
@param    int    切分开始处
*
@param    int    切分的长度
*
@return    int    切分后的字符串
*/

 
function msubstr($str, $start, $length=NULL)
{
    
preg_match_all("/./u", $str, $ar);
 
    
if(func_num_args() >= 3) {
      
$end = func_get_arg(2);
      
return join("",array_slice($ar[0],$start,$end));
    
} else {
      
return join("",array_slice($ar[0],$start));
    
}
}

Header函数前有输出的重定向问题(0 位领导批示)

一般做PHP页面重定向时,会用到header函数的location属性,然而在header函数前面有输出时就会报错

比如

<?PHP   
echo   "hello";   
header("Location:http://www.********.com");   
?>

解决的方法就是在这段代码前加上一个函数 ob_start();
代码如下:

<?PHP
ob_start();
echo   "hello";   
header("Location:http://www.********.com");   
?>

引用一下资料:

自PHP4起,可以通过一些输出缓冲函数来解决这个问题。代价是把所有向浏览器的输出都缓存在服务器,直到下命令发送它们。可以在代码中使用 ob_start() 及 ob_end_flush() 来实现这样的功能,或者通过修改php.ini中的output_buffering配置选项来实现,也可以通过修改服务器配置文件来实现。

WordPress制作标签云Tags单独页面(8 位领导批示)

Wordpress自带着wp_tag_cloud()函数,但只在页面侧边显示往往就不够了.需要一个单页来放所有的Tags

p.s.在搜索引擎优化SEO上,百度似乎对关键词TAGS更为偏爱

其实就是撰写一个新页面,它要应用一个名为tags.php的自定义模板.

tags.php的内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/*
Template Name: Tags
*/
?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
	<div class="narrowcolumn">
		<div class="post" id="post-<?php the_ID(); ?>">
			<h2>Tags</h2>
			<div class="entry">
				<?php wp_tag_cloud('smallest=12&largest=12&unit=px&number=5000');?>//smallest是最小字号,largest是最大字号,unit是单位,number是显示关键词个数,默认是45个
			</div>	
 
		</div>
	</div><!-- end narrwocolumn -->
<?php get_footer(); ?>
1
2
3
4
<?php
/*
Template Name: Tags
*/

这句一定不能少,要不撰写页面时就没有可以应用的模板文件。

把tags.php上传至模板目录

然后点击后台->撰写->撰写页面 页面标题为 tags。页面内容为空就可以了。 最重要的一步,选择页面模块,这里除了默认多出了一个新选项,就是刚刚才建好的tags.php模板,选择tags。因为我启用自定义的永久链接,所以页面缩略名也必不可少,还是老样子,起名为tags (起啥名都行)

发布 OK

然后给侧边栏sidebar加个链接 一切搞电。

DEMO地址:http://www.zdyi.com/index.php/tags

转载请注明

PHP导出Excel格式文件(xls)(1 位领导批示)

PHP导出Excel格式文件(xls),比想像中要简单的多,只需给PHP文件加一个文件头,filename 就是导出的xls文件名,当你点击这个文件的URL时,就会提示你下载xls文件了

header("Content-Type: application/vnd.ms-execl");
header("Content-Disposition: attachment; filename=info.xls");
header("Pragma: no-cache");
header("Expires: 0");

以下是全部代码:

  1. <?php
  2. header("Content-Type: application/vnd.ms-execl");
  3. header("Content-Disposition: attachment; filename=info.xls");
  4. header("Pragma: no-cache");
  5. header("Expires: 0");
  6. require_once(dirname(__FILE__)."/../include/config_base.php");
  7. require_once(dirname(__FILE__)."/../dede/config.php");
  8. require_once(dirname(__FILE__)."/../include/pub_datalist.php");
  9. $dsql = new DedeSql(false);
  10.  
  11.  
  12. echo "订阅日期"."\t";
  13. echo "订阅内容"."\t";
  14. echo "姓名"."\t";
  15.  
  16.  
  17. $dsql->SetQuery("Select * from `TableName` order by `id` desc");
  18. $dsql->Execute();
  19. $i = 1;
  20.  
  21. while($row = $dsql->GetArray())
  22. {
  23.  
  24.  
  25.     echo $row['uTime']."\t";
  26.     echo $row['uCont']."\t";
  27.     echo $row['uName']."\t";
  28.    
  29.     $i++;
  30. }
  31. ?>

Wordpress 自定义页面在首页显示内容(0 位领导批示)

Wordpress自定义页面如何在首页显示内容?这是今天制作wordpress模板时遇到的一个小问题

解决方法如下

  1. <?php
  2. $lastposts = get_posts('numberposts=1&post_type=page');
  3. foreach($lastposts as $post) :
  4. setup_postdata($post);
  5. ?>
  6. <h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>">关于</a></h2>
  7. <?php the_excerpt(); ?>
  8. <?php endforeach; ?>

把代码直接COPY到模板相应的位置

其中
numberposts 是指显示几条记录
post_type是指显示的类别

默认显示的是post 就与直接使用the_content() 是一样的效果

我这里使用的是the_excerpt(),方便以后显示摘要

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志