我怎么知道哪个用户在php

时间:2015-07-29 10:14:38

标签: php session

我想在我的网站中使用支付网关。我还在我的login.php会话变量中创建了用户会话ID。

的login.php

     <?php 
session_start();        
//get the data from the fileds;
        //check it.
        //and if it was correct, create a session id like the below
        //$_SESSION['login_user'] = $username;
        //redirect to the send.php
        ?>

现在,我有三个用于购买操作的php文件。请参阅以下代码:

send.php

<?php
include_once("sender.php");
$url = 'http://example.com/payment/gateway-send';
$api = ' Your-API ';
$amount = 1000;
$redirect = 'REDIRECT-PAGE';
$result = send($url,$api,$amount,$redirect);
if($result > 0 && is_numeric($result)){
$go = "http://example.ir/payment/gateway-$result";
header("Location: $go");
}
?>

get.php

<?php
include_once("sender.php");
$url = 'http://example.com/payment/gateway-result-second';
$api = ' Your-API';
$trans_id = $_POST['trans_id'];
$id_get = $_POST['id_get'];
$result = get($url,$api,$trans_id,$id_get);
?>

sender.php

<?php
function send($url,$api,$amount,$redirect){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&amount=$amount&redirect=$redirect");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
function get($url,$api,$trans_id,$id_get){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&id_get=$id_get&trans_id=$trans_id");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
?>

我的问题是,如何在这三个文件中使用login.php中的现有会话?

我有三个变量to have the amountto have the API value that Have given from payment gateway to me以及the REDIRECT-PAGE。当用户使用他的用户名和密码进入站点时,变量将发送到支付网关,如果变量值正确,支付网关会发送$result,如果有if($result > 0 && is_numeric($result))那么$go变量获取$go = "http://example.com/payment/gateway-$result";,然后用户就可以看到付款页面,他可以购买。

如果购买成功,付款网关会向get.php trans_idid_get个变量发送,如果它们正确无误,我应该保存买方用户名以及trans_idid_get。我应该如何在三个php文件中使用会话?

0 个答案:

没有答案