1

I m trying to access my session variable in backbone template which render with underscore.js

template : _.template(template)

i am working on login module . after login i set session in backend with php , which is working fine. session is started.

on success is set username with js, but it get vanish if someone refreshed the page so in case of refresh i bring up session variable.

Now i want to show session data in my template like

<li><a href="#" id="loginUser"><?php isset($_SESSION['username'])? echo $_SESSION['username']; ?></a></li>

but i am not getting those value ?

any help

thanks in advance

0

1 Answer 1

1

PHP Sessions do store the session_id in the cookie, (depending on the configuration, but default is:) nothing else.

E.g. setting $_SESSION['username'] does not send a cookie called username.

You cannot access these variables, they are stored in files on the server in /tmp directories, on my server it's

session.save_path => /var/lib/php5 => /var/lib/php5

And the option to save session in files is

session.save_handler => files => files

These variables can be obtained through php -i | grep session or phpinfo();.

You have to explicitly set a cookie using set_cookie(); to make it accessable through JavaScript.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.