2

index.js file

sessionStorage.setItem('name', 'xxxx');

login.php

<?php echo $_SESSION['name'] ?>

in my index.html page i get the name and store it in session using javascript

after the page will navigate to login.php in that i cant able to get the session variable

pls do help me to solve the issue.

6
  • javascript session and php session is both different things . you can not get local storeage value using PHP Commented Apr 1, 2015 at 12:02
  • if the object name is sessionStorage than it doesnt mean that it is storing values to server's session Commented Apr 1, 2015 at 12:02
  • sessionStorage and PHP $_SESSION are completely unrelated. The first one lives in the browser (client-side) and the second on the server (server-side). They can't interact directly with each other whatsoever. w3schools.com/html/html5_webstorage.asp Commented Apr 1, 2015 at 12:02
  • SessionStorage and LocalStorage allows to save key/value pairs in a web browser Commented Apr 1, 2015 at 12:03
  • session is based on browser only so .php file can able to get that browser session...?, set using js Commented Apr 1, 2015 at 12:05

2 Answers 2

1

In your index.html file create an ajax request and send it to any php file and in that php file set your session, Then in login.php file you can get you session easily.

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

Comments

1

javascript session( Local storage ) and php session is both different things . you can not get local storeage value using PHP.

sessionStorage(localStorage) is not create session . it save value in browser.

if you want to use this stored value to using in PHP then use ajax. get value from browser local storage and pass to PHP using ajax request

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.