Использование сеанса с Curl phpPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Использование сеанса с Curl php

Сообщение Anonymous »


I want to check if the user who logged in have role 'admin' and his com '1' so put it in session and it is working in every php files correctly but not when curl is happen it get as undefined. So I make file with sessions value and don't know how to fetch data from it

my getData.php :

session_start(); if ($_SESSION['login'] == false) { echo ' location.replace("../logout.php"); '; } define("SESSION_FILE", "session_data.txt"); function fetchDataWithSession($url) { // Check if the session data file exists and read its contents if (file_exists(SESSION_FILE)) { $sessionData = unserialize(file_get_contents(SESSION_FILE)); $_SESSION = is_array($sessionData) ? $sessionData : []; } // Initialize cURL session $ch = curl_init($url); // Set cURL options curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Pass the session data in the request headers $headers = [ 'Cookie: ' . http_build_query($_SESSION, '', '; ') ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // Execute cURL session and get the response $response = curl_exec($ch); // Check for cURL errors if (curl_errno($ch)) { // Handle error echo 'Curl error: ' . curl_error($ch); } // Close cURL session curl_close($ch); // Write the updated session data to the file file_put_contents(SESSION_FILE, serialize($_SESSION)); // End the session session_write_close(); return $response; } $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST']; $path1 = rtrim(dirname($_SERVER['REQUEST_URI']), '/'); $path = "$protocol://$host$path1/action.php"; // $sessionData = fetchDataWithSession($url . '?getSessionData=true'); $ispData = fetchDataWithSession($path . '?getIsp=true'); echo $ispData; die(); my action.php : the path lead my in this file .


Источник: https://stackoverflow.com/questions/780 ... h-curl-php
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»