简体   繁体   English

将PHP会话从一页传递到另一页

[英]Passing PHP session from one page to another

to be more relevant, i edit my question accordingly, i got ReqData.php and SendData.php where the first has input for id in a form using post the purpose of my code is to send the id from ReqData to SendData and decrypt the encrypted id which is done is ReqData using following code 为了更相关,我相应地编辑了我的问题,我得到了ReqData.php和SendData.php,其中第一个使用post以表格形式输入id,我的代码的目的是将id从ReqData发送到SendData并解密加密的使用以下代码完成的id是ReqData

function public_encrypt($plaintext){
$fp=fopen("mykey.pub","r");
$pub_key=fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
openssl_public_encrypt($plaintext,$crypttext, $pub_key );
return(base64_encode($crypttext));
}


$_SESSION['caesar'] = public_encrypt($_POST["inc"]);

and then go to SendData to be decrypted using 然后转到SendData以使用

function private_decrypt($encryptedext){
$fp=fopen("mykey.pem","r");
$priv_key=fread($fp,8192);
fclose($fp);
$private_key = openssl_get_privatekey($priv_key);
openssl_private_decrypt(base64_decode($encryptedext), $decrypted, $private_key);
return $decrypted; 
}

$encryp = $_SESSION['caesar'];
echo $encryp."<br/>";
$demo = private_decrypt($encryp);
echo "<br/>";
echo $demo;  

my problem is it can detect the session but it's not decrypting, for ur info, i'm using rsa encryption 我的问题是它可以检测到会话,但未解密,对于您的信息,我正在使用rsa加密

update: i var_dump($demo), it give me string(0) "", it supposed to be value i type in the id input box 更新:我var_dump($ demo),它给了我string(0)“”,应该是我在id输入框中输入的值

You need this 你需要这个

page1.php page1.php

<?php
session_start();

page2.php page2.php

<?php
session_start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM