zoukankan      html  css  js  c++  java
  • PHP 加密解密

    “计应134班   杨超”

    网页都是无状态的,如果要在新的网页中继续使用session,则需要把session从一个地方移到另一个地方,可能有些人已经想到了,我可以通过url传址的方式来调用它.而PHP有个处理session的变量,叫$_SESSION.于是将需要注册的session转换成一个数组。

    <?php 
    session_start(); 
    include “fun.php”; 
    $_SESSION[“userid”]; 
    $_SESSION[“username”]; 
    $_SESSION[“userpwd”]; 

    header("Location: http://$domain/process.php?s=".urlencode(passport_encrypt(serialize($_SESSION),"sessionkey"))); 
    ?> 

    用serialize将$_SESSION变成可存储的数据,然后通过passport_encrypt将这个数据加密,加urlencode的原因是因为$_SESSION加密时,有可能会产生像料想不到的编码。

    <?php 
    session_start(); 
    include “fun.php”; 
    $_SESSION=unserialize(passport_decrypt($_GET["s"],"sessionkey")); 
    header("Location: http://$domain/index.php"); 
    ?> 

    先用$_GET[“s”]获取URL的参数,然后用passport_decrypt将其解密,再用unserialize将其数据还原成原始数据,到了这步处理,你的网页就可能通过header自由跳转啦。

    加强版的process.php 

    <?php 
    session_start(); 
    include_once "fun.php"; 
    $_SESSION=unserialize(passport_decrypt($_GET["s"],"sessionkey")); 
    if((time()-$_SESSION["TIME"])>30){ 
    header("Location: http://$domain/ login.php"); 
    unset($_SESSION["USERNAME"]); 
    unset($_SESSION["PASSWORD"]); 

    else 
    header("Location: http://$domain/ index.php"); 
    ?> 

  • 相关阅读:
    hdu5608 function
    Codeforces Round #535 (Div. 3) 解题报告
    HDU4746 Mophues
    HDU5663 Hillan and the girl
    AtCoder Beginner Contest 117 解题报告
    GDOI2018D2T1 谈笑风生
    BZOJ4018: 小Q的幻想之乡
    牛客寒假算法基础集训营6 解题报告
    win32拖拽编程
    项目开发中的贝塞尔曲线
  • 原文地址:https://www.cnblogs.com/yangchao123/p/4939735.html
Copyright © 2011-2022 走看看