PDA

View Full Version : Session Handling Problems



blade226
14 Mar 2012, 2:26 AM
Hi,

i want to build an application with user handling. The login part send data to an php script. php returns success and starts a session. then a new site opens.

Now i want to create a menu. The points in the menu are depending on the rights in the session. My problem is now, that the variables in the session is not definied in extjs. In the world wide web i find a solution. But it not works.

Here is the example:

In extjs:
Ext.Ajax.request({
url: 'includes/getsession.php',

success: function (resp){
console.log(resp['recht1']);
}
});

in php (load and send session details):
<?php
@session_start();
echo '<script type="text/javascript">';
foreach ($_SESSION as $key => $value)
{
echo 'var '.$key.'="'.$value.'";';
}
echo '</script>';
?>

The following line is in ext:

<script type="text/javascript">var benutzer="192.168.156.143";var fehler="3";var angemeldet="1";var user="tester";var recht1="1";</script>

I also tried it with sending a json string from php to extjs. But i have not read the string in extjs.

I am grateful for any help

mitchellsimoens
14 Mar 2012, 11:14 AM
You should be able to return JSON, in your success handler decode the JSON into actual JS and save that in your app.

blade226
14 Mar 2012, 10:23 PM
I tried it also with json:

following string is passed


{benutzer:192.168.156.143,fehler:3,angemeldet:1,user:tester,recht1:1,}

But i'm a newbie in handling with extjs.

How can i turn the string in different variables?

Erikvip
14 Mar 2012, 11:16 PM
That's not valid JSON...just use the json_encode method in PHP, like this:



<?php
session_start();
echo json_encode($_SESSION);

blade226
14 Mar 2012, 11:28 PM
Now, I have a solution:

In extjs:

Ext.Ajax.request({
url: 'includes/getsession.php',
success: function(resp) {
var xyz = Ext.decode(resp.responseText);
console.log(xyz.recht1);
}
});

and in php
<?php
@session_start();
echo json_encode($_SESSION);
?>

Thank you for your help