Click here to Skip to main content
16,016,022 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all i've a problem with php session variables; in fact the issue is about a session variable that i've created in a php file and can't be accessed in another one requested by ajax.

below is the code of ajax.html the page from witch an ajax request is sent :
PHP
console.log('JQuery Ready')
     $.get(

        'http://localhost/php_files/ajax.php',
        false,

        function(data,status){


        console.log('data is'+data+' '+'status is ' +status);


        },
       'text'
        );


Next the Page Request ajax.php
PHP
if(isset($_SESSION['ses'])) echo 'session working';
else echo ' session not working';

And Finally the file Where i 've created the session variable :
PHP
session_start();

$_SESSION['ses']='session';
 echo $_SESSION['ses'];


what should i do to fix this problem ?

What I have tried:

i've tried to send data with ajax to a php page
Posted
Updated 28-Aug-17 21:12pm
v2
Comments
David_Wimbley 28-Aug-17 12:28pm    
I think you need to look at the php function json_encode. You are trying to access the session variable in a jquery ajax call .get but you aren't returning JSON which I think is why you can't access the variable in your jquery.

You should try echo json_encode($_SESSION['ses']);

php: json_encode - Manual
Member 13381828 29-Aug-17 3:09am    
no no the ajax function .get will request other data (text data) .
just in the php file ajax.php i want to understand why i can't acess this session variable .
Member 13381828 29-Aug-17 3:14am    
the ajax call exist in a ajax.html page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900