__get和__set类似于.net中的属性访问器,用于给类中的私有字段赋值。但注意,一般这种方式只能给一个字段赋值,当你的类中有多个字段的时候,建议使用function getProperty(){}和function setProperty(value)的形式(类似于java)。
所以上述代码你使用的方式完全错误:
class Employee
{
$name
public function __get()
{
return $name;//取得私有字段的值
}
public function __set($propValue)
{
this->$name = $propValue;//给私有字段赋值
}
}

事实上 JAVA等OOP语言中都是将属性设置为private的,其原因就是属性属于对象自身,所以不应该直接通过外界修改(会破坏对象自身的封装),之所以有魔术方法其实是为了通过某种接口来实现特定的属性修改(也就是符合某种条件才能对自身的属性进行修改),事实上对于java来说是采用的手动设置以及获取的方式设置,php中就更为简单了,提供了魔术方法来实现,另外提供__setter和__getter是魔术方法在某些设计模式中也有用到,这可能被设计为动态属性,也就是可以为对象在外部提供属性,而不需要在定义类时定义。

1.不一定是私有属性, :__get() is utilized for reading data from inaccessible members.
2.可以在__get中增加很多逻辑,有可能你用类中的一个数组类型的变量存了很多值,__get的时候,可以根据数组的key来取值,所以不一定是直接访问某个变量
3.你不设置__get函数的时候,不可访问的变量是受保护的

具体运用:


应该说 getter和setter的作用,最大的原因是为了让变量的修改和获取“可控”

在给属性赋值的时候,通过setter可以先对赋过来的值做一次合法性检查,以避免后面可能出现的错误!
在一个php框架中具体运用,我这人把它从我们的框架中抽离了出来示意一下:



————————————————用setParam 方法实现代码片段示例———————————————————————

getParam方法:

————————————————用__set和__get方法—————————————————


Result:
---------- 调试PHP ----------
TMController Object
(
    [abc] => Array
        (
            [weekscore] => ab
        )

)
scoreController Object
(
    [abc] => Array
        (
            [weekscore] => abc
        )

)

输出完成 (耗时 0 秒) - 正常终止

actInit.yaml
225: { type: 225, total: 60, daylimit: { 2010-1-28: 20, 2010-1-29: 20, 2010-1-30: 20, 2010-2-01: 20  } }
226: { type: 226, total: 60, daylimit: { 2010-1-28: 20, 2010-1-29: 20, 2010-1-30: 20, 2010-2-01: 20  } }


yaml_prase.php

<?php

    require_once "spyc.php";
    $content = @file_get_contents("./actInit.yaml");
    $yaml = Spyc::YAMLLoad($content);
    print_r( $yaml );

?>


输出array的结果如下,符合多维数组的输出要求:

Array
(
    [225] => Array
        (
            [type] => 225
            [total] => 60
            [daylimit] => Array
                (
                    [2010-1-28] => 20
                    [2010-1-29] => 20
                    [2010-1-30] => 20
                    [2010-2-01] => 20
                )

        )

    [226] => Array
        (
            [type] => 226
            [total] => 60
            [daylimit] => Array
                (
                    [2010-1-28] => 20
                    [2010-1-29] => 20
                    [2010-1-30] => 20
                    [2010-2-01] => 20
                )

        )

)

来源:
http://www.w3school.com.cn/php/func_string_chr.asp


八进制为什么以0开头,十六进制为什么以0X开头?这个是计算机编程语言里面的约定。大部分计算机高级语言涉及到这里都是遵循一样的标准,以便于区分。
马上上手:
注释:ascii 参数可以是十进制、八进制或十六进制。通过前置 0 来规定八进制,通过前置 0x 来规定十六进制。

<?php
echo chr(52);//十进制没有什么开头
echo chr(052);//八进制以0开头
echo chr(0x52);//十六进制就以0x开头
?>输出:

4
*
R

为此,同样的52输出不同的结果字母,看是简单,还是仍然需要注意一下,偶尔会犯大错的,呵呵!
常常需要比较时间,如几点比几点大,这儿用一个简单的方法比较:
需要比较:
二月七日凌晨到下午二点的时间不让用户领取奖品的比较,如下:


$nowDate=mktime(date('H'),date('i'),date('s'),date('m'),date('d'),date('Y'));

                $day = date("d");
    if($day == 7)

    {
    //第一天 2月7日
        $forbidden_begin = mktime(0,0,0,2,7,2010);//开始时间
        $forbidden_end = mktime(14,0,0,2,7,2010);//结束时间
        if(($nowDate>=$forbidden_begin)&&($nowDate<=$forbidden_end))
        {          
           return array('code'=>-1,'awardleft'=>0,'message'=>'兑换时间已过,敬请期待今日14点的机会哦!');
        }
    }

对于PHP页面,以下是代码片段,实践OK:


解释:
PHP页面强制浏览器不缓存的方法:
    (1)告诉客户端浏览器不使用缓存,HTTP 1.1 协议。
    header("Cache-Control: no-cache, must-revalidate");

    (2)告诉客户端浏览器不使用缓存,兼容HTTP 1.0 协议。
    header("Pragma: no-cache");

    (3)设置此页面的过期时间(用格林威治时间表示),只要是已经过去的日期即可。
    header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");

    (4)设置此页面的最后更新日期(用格林威治时间表示)为当天,可以强迫浏览器获取最新资料。
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");


参考:http://blog.sina.com.cn/s/blog_8002308e0100xrmv.html
缘起:

莫莫(406052573)  10:07:06
这么写了,怎么还输出那么多tr出来了

对于table布局实在是没有div布局li lu来布局好,table无非是tr /tr一行的方式,如果每行输出4个产品,如下:注意:
<tr>

echo "</tr><tr>";
是  if($i%4 ==0);

</tr>

详细点,如下:

      
<div style="height:930px">
         <table  border="0"  cellspacing="0" cellpadding="0" style="color:#A61F24; font-size:12px;">
          <tr>
             <?php
                $count = count($rows);
                $i=0;
                foreach($rows as $key =>$values)
                {
                    $i++;
              ?>



          。。。。循环产品输出


              <?php
                if($i%4 ==0)
                {
                    echo "</tr><tr>";
                }
              }
              ?>
              </tr>
      </table></div>








为何加div是用来固定高度后,下面加入翻页等。
对其的问题:
http://www.jackxiang.com/post/2375/
兄弟我经常需要用到bash 的好用的快捷键,ctrl+l:清屏,相当于clear。
装了个金山词霸(当然盗版啦),发现ctrl+l:清屏没有用了,于是在软件设置里面有个朗读的快捷键也是ctrl+l,去掉了就ok了。嘻嘻
http://www.zendstudio.net/archives/zend-studio-7-1-and-aptana-are-good-brothers/
上面说的都是管理员权限下的安装!!!其余非管理员的用户似乎有问题的,我试了下。


插件下载地址:
http://www.aptana.org/studio/plugin

Aptana Studio 2.0 Plugin Installation Instructions

Eclipse Update Site: Installing via Aptana or Eclipse

Update Site:
http://download.aptana.org/tools/studio/plugin/install/studio

Detailed Directions:

   1. From the Help menu, select Install New Software... to open an Install pop-up window.
   2. In the Work with: text box of the Install window, type the URL http://download.aptana.org/tools/studio/plugin/install/studio for the update site, and hit the Enter key.
   3. In the populated table below, check the box next to the name of the plug-in, and click the Next button.
   4. Click the Next button to go to the license page.
   5. Choose the option to accept the terms of the license agreement, and click the Finish button.

Manual Installation: Download the Plugin Update Site

   1. Download Studio 2.0 Plugin zip.
   2. Open Eclipse distribution, and go to Help -> Install New Software....
   3. Click the Add... button to open the Add Site window.
   4. Click the Archive... button, and select the file saved in step 1.
   5. Select the appropriate plugins to install, and click Next -> Next.
   6. Click the Finish button.


date测试的时候容易出现如下情况,data-s 查询了下,可以实现如下,
date -s "2010-1-1 16:11:21"

但是其他同事也用到date("Y-m-d H:i:s"),就会说:我在调试c程序,是谁修改了服务器时间?我说:我在测试。
于是就有人说没有必要通过date -s来修改整个服务器的时间,而是重写php的该date函数,但是我一旦重写,会提示错误的。
于是又有人说可以关闭掉,date()函数,于是查了下国外的,如下:

Q. I run a small Apache based webserver for my personal use and it is shared with friends and family. However, most script kiddie try to exploit php application such as wordpress using exec() , passthru() , shell_exec() , system() etc functions. How do I disable these functions to improve my php script security?

A. PHP has a lot of functions which can be used to crack your server if not used properly. You can set list of functions in php.ini using disable_functions directive. This directive allows you to disable certain functions for security reasons. It takes on a comma-delimited list of function names. disable_functions is not affected by Safe Mode. This directive must be set in php.ini For example, you cannot set this in httpd.conf.


Open php.ini file:
# vi /etc/php.ini
Find disable_functions and set new list as follows:
disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source !

Save and close the file. Restart httpd:
# service httpd restart



Warning: date() has been disabled for security reasons in  /*/*/datetest.php on line 5



<?php
function date($str)
{

return "2009-12-11 21:09:35";
}
echo date("Y-m-d H:i:s");

?>

出现:
[/usr/local/tads/htdocs/qdkj/src/view]# php datetest.php

Fatal error: Cannot redeclare date() in /data/*/*/src/view/datetest.php on line 6
I think:
PHP already has a date() function and you cannot overwrite existing functions in this language. Rename your function and it will work. Or wrap it in a class and it will work as well.


于是,我在想啊,现在如果有人在用php的date,我给大家把这个date函数给disable了,大家回不会来找我呢?拭目以待。。。

EOF
**  表示中文:


**1000.txt
**1001.txt
**1002.txt
.
.
.
在Linux下想把中文**去掉,如下:

mv *1001.txt 1001.txt
mv *1002.txt 1002.txt
mv *1003.txt 1003.txt
mv *1004.txt 1004.txt
mv *1005.txt 1005.txt
mv *1006.txt 1006.txt
mv *1007.txt 1007.txt
mv *1008.txt 1008.txt
.
.
.
如何生成如上的语句?
步骤:
1.先出一个统一的文件shell.sh:


mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt


2.用awk命令:

num=1000;
cat shell.sh |awk -F"1000" '{print $1 '$num'+NR $2 '$num'+NR  $3}'


生成如下:

mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
.
.
.
默认div的属性值都是static,静态。就不用多说了。最关键的是
relative(相对)以及absolute(绝对)。
往往我们如果是COPY别人的代码,会把absolute属性与left、top配合起来制作相关的“悬浮层”效果。然而有时候我们需要针对某一个容器的悬浮效果,而不是针对窗口的。这时候通过高度、宽度的计算不但麻烦,而且几乎无法完美实现效果。我一开始也无能为力,后来发现只要把其上一级的样式属性 position设置为relative就可以了。
也就是说,position的属性值的效果,直接受其容器样式中position属性值影响。
例如如下A-B的嵌套结构




当A的position为relative时,B的position为absolute才有效。这时候left:0、top:0就不再针对窗口文档,而是针对id为A的这个div了。
这样在开发一些基于B/S应用程序的时候,就能很方便的添加一些UI元素,例如某一个活动层的关闭按钮等。


备注:
position:absolute这个是绝对定位;
是相对于浏览器的定位。
比如:position:absolute;left:20px;top:80px; 这个容器始终位于距离浏览器左20px,距离浏览器上80px的这个位置。

position:relative是相对定位,是相对于前面的容器定位的。这个时候不能用top left在定位。应该用margin。

比如:


当1固定了位置。1的样式float:left;width:100px; height:800px;
2的样式为float:left; position:relative;margin-left:20px;width:50px;
2的位置在1的右边,距离120px
   一直在firefox下用firebug调试web UI,在IE下简直就是噩梦,njj发现了IE版的firebug Internet Explorer Developer Toolbar,立即告诉了我,IE下调试兼容页面的苦难日子终于过去了。
http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&DisplayLang=en

---------------------------------------------------------------------------------------------------------------------------------------------------------
   这个工具的用法,我还在探索中……
和firefox下的firebug一样的在IE上可以使用:
http://www.cnblogs.com/hooray/archive/2011/04/21/2023289.html
---------------------------------------------------------------------------------------------------------------------------------------------------------
IE下使用firebug:
把下面这段代码复制到地址栏,然后运行即可。
firebug官网:https://getfirebug.com/



_______________________________________________________________________________________
Add Time: 2014-03-21 (下面都不是问题,用fiddler2直接加载进去即可,可以修改下高度,查看下样式足够了。)
如果你想让页面默认就有一个firebug的小按钮进行调试,那直接加一句:
<head>
...
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
...
</head>
虽然现在能在IE是使用fb了,但是IE上的fb缺陷还是有的,比如html代码不会实时更新,尤其是在测试jquery插件的时候就无奈了。
不过总的来说,firebug for ie还是解决了我们在IE上检查样式及代码提供了一个很好的工具。
1.由于50上的qmail不需要验证就可以发信,有了验证反而出现错误,最后在133那台机器就可以了,auth login afeng133@afeng133.sina.net 123qwe(Base64),然后给126(xxx108@126.com)发了信可以收到,不错不错,以下文件存为utf8 格式:

如果有获取whoami之类的,修改配置文件 php.ini 把exec的执行权限放开!

smtp.class.php:

<?php
set_time_limit(120);
class smtp_mail
{
    var $host="";          //主机
    var $port="25";          //端口 一般为25
    var $user="";          //SMTP认证的帐号
    var $pass="";          //认证密码
    var $debug = false;   //是否显示和服务器会话信息?
    var $conn;
    var $socket="";
    var $result_str;      //结果
    var $in;          //客户机发送的命令
    var $from_r;          //真实的源信箱,一般与smtp服务器的用户名一样,否则可能由于smtp服务器的设置而发送不成功
    var $mailformat=0; //邮件格式 0=普通文本 1=html邮件

    function smtp_mail($host,$port,$user,$pass,$debug=false)
    {
        $this->host  = $host;
        $this->port   = $port;
        $this->user   = base64_encode($user);
        $this->pass   = base64_encode($pass);
        $this->debug  = $debug;
        $this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);  //具体用法请参考手册
        if($this->socket)
        {
              //$this->result_str  =  "创建SOCKET:".socket_strerror(socket_last_error());
              $this->result_str  =  "创建SOCKET:".iconv("GBK","UTF-8//TRANSLIT//IGNORE", socket_strerror(socket_last_error()));
              $this->debug_show($this->result_str);
        }
        else
        {
            exit("初始化失败,请检查您的网络连接和参数");
        }
        $this->conn = socket_connect($this->socket,$this->host,$this->port);
        if($this->conn)
        {
            $this->result_str  =  "创建SOCKET连接:".iconv("GBK","UTF-8//TRANSLIT//IGNORE",socket_strerror(socket_last_error()));
            $this->debug_show($this->result_str);
        }
        else
        {
            exit("初始化失败,请检查您的网络连接和参数");
        }
        $this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
        $this->debug_show($this->result_str);
    }

    function debug_show($str)
    {
        if($this->debug)
        {
            echo $str."<p>\r\n";
        }
    }

    function send($from,$to,$subject,$body)
    {
        if($from == "" || $to == "")
        {
            exit("请输入信箱地址");
        }
        if($subject == "") $sebject = "无标题";
        if($body    == "") $body    = "无内容";

        $All          = "From:".$from."\r\n";
        $All          .= "To:".$to."\r\n";
        $All          .= "Subject:".$subject."\r\n";
        if($this->mailformat==1) $All.= "Content-Type: text/html;\r\n";
        else $All .= "Content-Type: text/plain;\r\n";
        $All          .= "charset=gb2312\r\n\r\n";
        $All          .= $body;
        /*
          如果把$All的内容再加处理,就可以实现发送MIME邮件了
          不过还需要加很多程序
        */

        //以下是和服务器会话
        $this->in       =  "EHLO HELO\r\n";
        $this->docommand();

        $this->in       =  "AUTH LOGIN\r\n";
        $this->docommand();
        $this->in       =  $this->user."\r\n";

        $this->docommand();

        $this->in       =  $this->pass."\r\n";
        $this->docommand();

        if(!eregi("235",$this->result_str)){
           $this->result_str = "smtp 认证失败";
           $this->debug_show($this->result_str);
           return 0;
        }

        $this->in       =  "MAIL FROM:<".$from.">\r\n";
        $this->docommand();

        $this->in       =  "RCPT TO:<".$to.">\r\n";
        $this->docommand();

        $this->in       =  "DATA\r\n";
        $this->docommand();

        $this->in       =  $All."\r\n.\r\n";
        $this->docommand();

        if(!eregi("250",$this->result_str)){
           $this->result_str = "邮件发送失败";
           $this->debug_show($this->result_str);
           return 0;
        }

        $this->in       =  "QUIT\r\n";
        $this->docommand();

        //结束,关闭连接
        return 1;
    }

    function docommand()
    {
        socket_write ($this->socket, $this->in, strlen ($this->in));
        //$this->debug_show("客户机命令:".iconv("GBK","UTF-8", $this->in));
        $this->debug_show("客户机命令:".iconv("GBK","utf-8//TRANSLIT//IGNORE", $this->in)); //防止报错:Notice: iconv(): Unknown error (84)
        $this->result_str = "服务器应答:<font color=#cc0000>".iconv("GBK","UTF-8//TRANSLIT//IGNORE", socket_read ($this->socket, 1024))."</font>";
        $this->debug_show($this->result_str);
    }

} //end class
?>

sendmail.php:

<?php
  header("Content-type: text/html; charset=utf-8");
?>
<?php
  include("smtp.class.php");
  //$mails=new smtp_mail("220.181.15.111","25","xxx108@126.com","********");
  $mails=new smtp_mail("220.181.15.111","25","xxx108@126.com","********",true);
  $date = date("Y-m-d H:i:s");
  if($mails->send("xxx108@126.com","xxx108@126.com","有人于".$date."登录服务器","请注意是否自己在该时间登录。","登录时间。"))
  {
    echo "发送成功!";
  }else{
      echo "邮件服务器忙,请稍候再试试";
  }
?>


如果有获取谁的exec函数加上(修改配置文件 php.ini 把exec的执行权限放开!):

这个程序的实质是模仿如下终端操作:

telnet smtp.sina.net 25
Trying 202.108.37.33...
Connected to smtp.sina.net.
Escape character is '^]'.
220 sina3-197.sina.net ESMTP - qmail-1.04
helo sina.net
250 sina3-197.sina.net
AUTH LOGIN
334 VXNlcm5hbWU6
ZWFzdHN1bkBlYXN0c3VuLnNpbmEubmV0
334 UGFzc3dvcmQ6
MTIzcXdl
235 验证通过- authentication successfully
data
503 请先用 RCPT - RCPT first (#5.5.1)
mail from:<xxx108@126.com>
250 Mail OK
rcpt to:<xxx108@126.com>  
rcpt to:<372647693@qq.com>      //第二个抄送人
250 Mail OK
data
354 End data with <CR><LF>.<CR><LF>
From: Mail test <372647693@qq.com>
Sender: jackxiang <xxx108@126.com>
To: xxx108@126.com
Cc: 372647693@qq.com
Subject: mail testing mail title

This is mail content...

.
250 Mail OK queued as smtp1,C8mowEDpO0uNr0dUwfhiAA--.1433S3 1413984769

(最后这个小数点一定要加上)

此时,372647693@qq.com也会收到,这个cc:就是抄送人,在邮件标题里体现,真正发还是在rcpt to:<372647693@qq.com>      //第二个抄送人。

邮件标题:
mail testing mail title
发件人:Mail test<372647693@qq.com> (由 xxx108@126.com 代发)
收件人:我<xxx108@126.com>
抄送人:372647693<372647693@qq.com>
This is mail content...

QQ邮箱:
发件人:我自己的邮箱 <372647693@qq.com>(由 xxx108@126.com 代发)
时   间:2014年10月22日(星期三) 晚上9:46  
收件人:xdy108 <xxx108@126.com>
抄   送:回忆未来-向东-Jàck <372647693@qq.com>
This is mail content...

————————————————————————————————————————————————————————
以下如果打开$mails=new smtp_mail("smtp.sina.net","25","eastsun@eastsun.sina.net","123qwe","false");  //false
可以看见其到底是如何进行会话的,如下:
创建SOCKET:您的主机中的软件放弃了一个已建立的连接。
创建SOCKET连接:您的主机中的软件放弃了一个已建立的连接。

服务器应答:220 smtp-5-32.sina.net ESMTP - qmail-1.04

客户机命令:EHLO HELO

服务器应答:250-smtp-5-32.sina.net 250-AUTH=LOGIN 250-AUTH LOGIN 250-PIPELININGJH 250 8BITMIME

客户机命令:AUTH LOGIN

服务器应答:334 VXNlcm5hbWU6

客户机命令:ZWFzdHN1bkBlYXN0c3VuLnNpbmEubmV0

服务器应答:334 UGFzc3dvcmQ6

客户机命令:MTIzcXdl

服务器应答:235 验证通过 - authentication successfully

客户机命令:MAIL FROM:xiaoqian@staff.sina.com.cn

服务器应答:250 eastsun@eastsun.sina.netok

客户机命令:RCPT TO:xiangdong2@staff.sina.com.cn

服务器应答:250 ok

客户机命令:DATA

服务器应答:354 请继续 - go ahead

客户机命令:From:xiaoqian@staff.sina.com.cn To:xiangdong2@staff.sina.com.cn Subject:我来个中文测试一下,怎么就不正常了呢,哈哈。。向东 Content-Type: text/plain; charset=gb2312 我来个中文测试一下,这里是信的内容!!! .

服务器应答:250 ok 1212053255 qp 74366

客户机命令:QUIT

服务器应答:221 smtp-5-32.sina.net

发送成功!


对用户名和密码的Base64编码方法:

<?php
$user="xiangdong2@staff.sina.com.cn";          
$pass="xiangdong";
$user   = base64_encode($user);
$pass   = base64_encode($pass);
echo $user."\n";
echo $pass."\n";
?>




[root@vm0000055 ~]# telnet staff.sina.com.cn 110
Trying 10.210.98.10...
Connected to staff.sina.com.cn (10.210.98.10).
Escape character is '^]'.
+OK staff-jes1.sina.com.cn POP3 service (Sun Java(tm) System Messaging Server 6.2-3.04 (built Jul 15 2005))
xiangdong2
-ERR Unrecognized command
xiangdong2@staff.sina.com.cn
-ERR Unrecognized command
USER xiangdong2
+OK Name is a valid mailbox
pass xiangdong  
+OK Maildrop ready
AUTH
-ERR Unrecognized command
LIST
+OK scan listing follows
1 1675
2 8490
3 3004
4 625
5 650
6 1877
7 1928
8 1939
9 2131
.
RETR 1
+OK 1675 octets
Return-path: <jinsong@staff.sina.com.cn>
Received: from sina123123123 ([10.218.26.58]) by staff-jes1.sina.com.cn
(Sun Java System Messaging Server 6.2-3.04 (built Jul 15 2005))
id <0KLS00I01MFE7V00@staff-jes1.sina.com.cn>
(original mail from jinsong@staff.sina.com.cn); Thu,
25 Jun 2009 20:01:15 +0800 (CST)
Received: from sina123123123 ([10.218.26.58]) by staff-jes1.sina.com.cn
(Sun Java System Messaging Server 6.2-3.04 (built Jul 15 2005))
with ESMTPA id <0KLS00OCGMQ2Q1B0@staff-jes1.sina.com.cn>; Thu,
25 Jun 2009 20:01:14 +0800 (CST)
Date: Thu, 25 Jun 2009 20:01:34 +0800
From: =?GB2312?B?wbq+osvJ?= <jinsong@staff.sina.com.cn>
Subject:
=?gb2312?B?vfHM7M/Czuc2o7owMLnHuMnN+LnK1c+jrNbQtefQxbPGueO2q7P2yqHCt9PJxvez9rnK1c8g1OyzybulwarN+NO1yPs=?=
To: cpyw <cpyw@staff.sina.com.cn>, sinamail <sinamail@staff.sina.com.cn>,
platform <platform@staff.sina.com.cn>
Message-id: <200906252001339840407@staff.sina.com.cn>
MIME-version: 1.0
X-Mailer: Foxmail 6, 9, 201, 16 [cn]
Content-type: text/plain; charset=gb2312
Content-transfer-encoding: base64

vfHM7M/Czuc2o7owMLnHuMnN+LnK1c+jrNbQtefQxbPGueO2q7P2yqHCt9PJxvez9rnK1c8g1Oyz
ybulwarN+NO1yPsNCmh0dHA6Ly90ZWNoLnNpbmEuY29tLmNuL3QvMjAwOS0wNi0yNS8xOTMyMzIx
MjIyNS5zaHRtbA0KaHR0cDovL3RlY2guc2luYS5jb20uY24vdC8yMDA5LTA2LTI1LzE5MTYzMjEy
MjEzLnNodG1sDQpodHRwOi8vdGVjaC5zaW5hLmNvbS5jbi9pLzIwMDktMDYtMjUvMTkyNTMyMTIy
MTguc2h0bWwNCiAJCQkJDQotLS0tLS0tLS0tLS0tLQ0Kwbq+osvJDQoNCnNpbmG7pbavyefH+NTL
06rWp7PW1+kNCg0Ktee7sKO6MDEwo602MjY3NjgxMQ0KDQrK1rv6o7oxMzcxNzkwMzMxOQ0KDQrT
ys/ko7pqaW5zb25nQHN0YWZmLnNpbmEuY29tLmNuIA0KDQpNU046cm9zZWxpYW5nanNAaG90bWFp
bC5jb20NCg0KUVE6NjQyNzkyMjI0DQoyMDA5LTA2LTI1DQo=








PHP通过Socket来发送网页Post请求和Get请求Ok代码:

如果没有Host在里面[fwrite($sock, "Host: upload.com\r\n");],则会出现:
51 [Mon Jun 20 18:12:19 2011] [error] [client 172.25.38.70] client sent HTTP/1.1 request without hostname (see RFC2616
        section 14.23): /upload/upload.cgi


判断refer啥的,这块涉及到php的curl传refer,请参考:
伪造refer:  https://jackxiang.com/post/4022/
伪造Host绑定来源:https://jackxiang.com/post/4423/
PHP7的session设置问题只在php.ini里设置不生效,得在php-fpm.conf里包含文件里设置:
cat etc/php-fpm.d/www.conf
php_value[session.save_handler] = files
php_value[session.save_path] = /data/tmp/session

来自:https://typecodes.com/web/php7configure.html

===========================================================
php session默认存放位置,php.ini 里面的 session.save_path
采用的是php的缓存。这部分可以自己写,例如把session放到某个cache服务中(redis,memcached)
参考:http://www.php.net/manual/zh/book.session.php




請問各位 php 前輩,有無可能用 include 或 require 整個目錄下的檔案

例:

require(models/survey/SurveyItem.inc');

改成

require(models/survey/');


另外請問一下,同一 php 檔案下是否不能出現 2次以上
相同的 function?

例:

在一php檔裡有 session_start ,而 require的檔案裡 也有 session_start
, 在我local 端的server裡,跑起來會出現

Notice: A session had already been started - ignoring session_start() in C:\xxxxxxxxx.php on line 43

但在虛擬主機上又很正常,為何會如此呢?

感謝~~

在XP系统下,我配置了session
如下:
session.save_path = "C:/temp"
session.auto_start = 1


将安全等级调低,在php.ini中
作者: freelin 发布日期: 2004-5-26
之前我从来没设过安全等级,请问是哪一选项?谢
作者: suse 发布日期: 2004-5-26
php.ini中error_reporting = E_ALL & ~E_NOTICE
或在程序开头加上:
error_reporting(E_ALL & ~E_NOTICE);
还不行还是你配置有问题。。。
            以本人性格,就是喜欢抄别人的,这次来点自己的吧,其实也是大家的,一哥们去百度参加面试的题目。。。呵呵,见笑!
如百度4
baidu4:
11 11 11 22 33 44 ...
baidu4中有一行以空格隔开的十进制数,用shell编程求出它们的和并打印。
他shell不行,他用php写了一个。
求正解:
我写了一个如下:
FILE="baidu4"
read line < $FILE
r=0
for num in $line;do
r=$(expr $num + $r)
done
echo $r
在猜朋友写的php,我也写一个PHP的:
<?php
$lines = file('baidu4');
$result2 = 0;
foreach ($lines as $line_num => $line) {
  $result = explode(" ",$line);
  for($i=0;$i<count($result);$i++)
    {
    $result2 += $result[$i];
    }
  echo $result2;        
}
?>

再来个awk的:
#!/usr/bin/awk -f
BEGIN{}
        {
                sum = 0;
                for (i=1; i<=NF; i++)
                {
                        sum += $i;
                }
                printf("count == [%d]\n",  sum);
        }
END{}



我在用c语言写一个吧:
太难用指针,让玩得好的指导下写了一个感谢罗玉峰,可以求多行的结果呢:
#include <string.h>
#include <stdio.h>
char *pp,*p;
char linebuf[4096];
char tmp[1024];
int i,tmpl;
int  main(void)
{
FILE *fp;
if ( ( fp = fopen ("baidu4", "r") ) == NULL )
{
       printf("cant't open the baidu4 file ");
       exit(0);
}
while(fgets(linebuf,4096,fp))
{    
linebuf[strlen(linebuf)-1] = 0;
pp=linebuf;
tmpl=0;
p=strchr(pp,' ');
while(p != NULL)
{
  strncpy(tmp, pp, p-pp);
  printf("tmp=[%s]\n", tmp);
  tmpl+=atoi(tmp);
//  memset(tmpl, 0x00, sizeof(tmpl));
  memset(tmp, 0x00, sizeof(tmp));
  pp=p+1;
  p=strchr(pp,' ');
}
if (*pp)
{
  strcpy(tmp, pp);
  tmpl+=atoi(tmp);
  printf("tmp=[%s]\n", tmp);
}
printf("total=%d",tmpl);
memset(linebuf, 0, sizeof(linebuf));
//memset(tmpl, 0, sizeof(tmpl));
printf("----------------\n");
}
return 0;
}
那位哥们能用java写个就完美了,:-)
这位留言的哥哥真高,用sed替换和管道导入计算器bc来计算,确实很高:

Exaple: baidu4
11 11 11

jackxiang@jackxiang-laptop:~$ sed 's/ /+/g' baidu4
11+11+11
jackxiang@jackxiang-laptop:~$ sed 's/ /+/g' baidu4| bc
33
jackxiang@jackxiang-laptop:~$

感谢那个留言的哥们,bc
echo " 930307 -   921336"|bc

[/home/jackxiang/bc]# echo " 930307 -   921336"|bc
8971
   将10进制数转换成16进制数

  比如转换 65535 为 16进制

  echo 'obase=16; 65535' | bc

  得到 FFFF



echo 'obase=16; ibase=8; 177777' | bc

  可以直接将八进制的数177777变成十六进制,也是FFFF
分页: 26/26 第一页 上页 16 17 18 19 20 21 22 23 24 25 26 最后页 [ 显示模式: 摘要 | 列表 ]