Search code examples
phpgoogle-app-enginesessionvariablesmemcached

How to use Memcache session in php gae


I was wondering if any one could teach me how to use sessions in GAE php. I know that the usual method is to use session_start() in every page that wants the session to carry over and then assign variables using $_SESSION['name'].

But PHP on GAE is a bit confusing at times.

https://developers.google.com/appengine/docs/php/?hl=en#Sessions

I have some idea on memcache but dont know how to use it to store session variable. Can any one tell how I can create a session variable so that when I redirect using header the variables will be present too.

Eg.

First.php

session_start();
$_SESSION['name'] = Abilash;

header('location: second.php');

Second.php

session_start(); echo $_SESSION['name']; // should output Abilash.

Now how do I do that in GAE. Whenever I try to redirect using header the redirected page loads but the session variables are not passed through.


Solution

  • You should not need to do anything to get sessions working, as we automatically put them into memcache by default.

    Perhaps the session cookie is not being passed by your browser for the second request. I'd turn on developer tools in chrome to make sure you see that the cookie is on the request and I'd also output the result of session_start() to check it's returning true.