dongyangzhi0687 2018-12-03 15:43
浏览 177

在Laravel 5.5中无法使用PHP cURL获取请求的会话

I have an issue on Laravel 5.5. I have a web application that acts as a gateway. My partner can request to my gateway via cURL or HTTP.

  1. The first step, when my partner requests (via cURL) to my gateway passing the master data and credential. Then I validate those data; if the data is correct, I will store request data in the session. And then response back session key.
  2. When a partner gets session key, they will redirect and pass session key back to my web page to input more detail info base on master data that they submit via cURL last time. But when they redirect to my web page via the browser, I can't get the session back. It seems the session key that I use when cURL request and redirect by the browser are different.

But when I try to request validate master data and credential in postman and get the session back by the postman, I can get it back.

My Sample Testing by using fix session key:

TestingController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Hash;
use Session;

class TestingController extends Controller
{
    public function test1() {
        $testing = "Testing";
        Session::put("ABC", $testing);
        return "Key: ABC, Value: $testing";
    }

    public function test2() {
        $testing = Session::get("ABC");
            return "Key: ABC, Value: $testing";
        }
    }
}

web.php (route)

Route::post('/test1', 'TestingController@test1');
Route::get('/test2', 'TestingController@test2');

Sample request from php

<?php

$authenticate = "http://localhost/test1";
$redirect = "http://localhost/test2";
$ref_gen = date("Ymdhisa");
if($_POST['submit']) {
    $param = array(
        'username'=> 'testing',
        'secrete' => '85a731b9d40388ad0a998d84e7e9de958c2',
        'order_referenceno' => $ref_gen,
    );
    $content = json_encode($param);
    $curl = curl_init($authenticate);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type:application/json"));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $response = curl_exec($curl);
    var_dump("response:".$response);
    if ($response === FALSE) {
        echo "cURL Error: " . curl_error($curl);
    } else {
        header("Location: ".$redirect."?session=$response");
    }
}

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
    • ¥15 怎么让wx群机器人发送音乐
    • ¥15 fesafe材料库问题
    • ¥35 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功