Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a banner at my PHP website which can be closed by clicking on an image, using Javascript. But when a user reloads the page, or visits another page, the banner shows again, which I want to prevent. I need a way to access the session variable from that Javascript, in order to do it. Is there any way I can do this, or is there some way other than using the session variable?

I have seen that there are already some questions concerning this topic, but I haven't been able to succeed using those answers.

share|improve this question
1  
Use Ajax and call a Php script to get/modify/delete your PHP variables. Oh didn't see how it worked, you don't even need Ajax since user reload page, just use a session variable. – Michael Laffargue Sep 5 '12 at 12:28
use a cookie, when user clicks set a certain cookie and based on that cookie you don't display the banner directly from db – Mihai Iorga Sep 5 '12 at 12:29

1 Answer

up vote 2 down vote accepted

You can't access the session variables directly, because they are held on the server and not on the client, where your JavaScript executes.

You can, however, send an AJAX request back to your server, requesting to set that session variable.

Another option would be to set a cookie value and retrieve that cookie value for the next site request.

In my opinion the first option is better, but depending on your system, the second approach might be more suitable in your case.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.