<?php 
$key = "This is supposed to be a secret key !!!"; function keyED($txt,$encrypt_key) 

$encrypt_key = md5($encrypt_key); 
$ctr=0; 
$tmp = ""; 
for ($i=0;$i<strlen($txt);$i++) 

if ($ctr==strlen($encrypt_key)) $ctr=0; 
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); 
$ctr++; 

return $tmp; 
} function encrypt($txt,$key) 

srand((double)microtime()*1000000); 
$encrypt_key = md5(rand(0,32000)); 
$ctr=0; 
$tmp = ""; 
for ($i=0;$i<strlen($txt);$i++) 

if ($ctr==strlen($encrypt_key)) $ctr=0; 
$tmp.= substr($encrypt_key,$ctr,1) . 
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); 
$ctr++; 

return keyED($tmp,$key); 
} function decrypt($txt,$key) 

$txt = keyED($txt,$key); 
$tmp = ""; 
for ($i=0;$i<strlen($txt);$i++) 

$md5 = substr($txt,$i,1); 
$i++; 
$tmp.= (substr($txt,$i,1) ^ $md5); 

return $tmp; 
} $string = "Hello World !!!"; // encrypt $string, and store it in $enc_text 
$enc_text = encrypt($string,$key); // decrypt the encrypted text $enc_text, and store it in $dec_text 
$dec_text = decrypt($enc_text,$key); print "Original text : $string <Br>\n"; 
print "Encrypted text : $enc_text <Br>\n"; 
print "Decrypted text : $dec_text <Br>\n"; 
?>
自己看看吧,也许对你有帮助。

解决方案 »

  1.   

    上面是一段php加密解密的代码,我还看到过一篇相关文章介绍,网址如下,你看看了,也许对你有帮助。
    http://www.ccidnet.com/tech/app/2001/08/07/58_2902.html
      

  2.   

    1.我的代码如下(从书上取):    <?php
    session_start();
    session_set_cookie_params(time()+8600,'/cooliepath','johnny.com');
    $cookie=session_get_cookie_params();
    echo $cookie[lipath];
    echo $cookie[lifetime];
    echo $cookie[domain];
     $aa="dd";
     $bb="bb";   
    session_register("aa");
    session_register("bb");
    session_unregister("aa");
        
       ?>请问 'cooliepath'是存放session id 的cookie地址,但'/cooliepath'究竟是相对于哪个路径的地址,(我怎么
    找也找不到)。为什么 echo $cookie[lipath]; 的输出是空。
    2.我目前的session放置位置是 c:\program files\apache group\apache\htdocs\anfield.com\
       但我想修改存放路径(函数方法)  我用:session_save_path('c:\program files\apache group\apache\htdocs\test');
      希望把session放到和anfield.com同一目录的test文件夹里面,我做了很多尝试,都失败,我应该怎么写
      路径呢?