I have a session[‘password’]. I would like to get the session value and use it to validate against user’s input.
if(opw != $_session['password']){
errors[errors.length] = "Sorry, password does not match.";
}
This is what I have been trying, however if I input this they do not read the session. And ignore this conditions. How do I actually insert session value into Javascript?
As the other answers have suggested, you have to embed your PHP session value into the javascript when the page is generator. But the others have forgotten one important thing – you have to generate VALID javascript or your entire script will get killed with a syntax error.
Note the call to json_encode – it’s not just enough to output the password string. You have to make sure that the password becomes a VALID javascript string, which json_encode ensures.