0

I am doing movie website.

I'm asking for the "base" script to check if certain user is logged in or not to have acess to the videoplayer.

Problem Statement: At present, it shows even if the user is not logged in, I want to change that.

So far i came up with this code, but it always return true, because my var takes the value of the $_Session as text.

  <p>Click the check user:</p>

  <button onclick="checkuser()">Try it</button>

  <p id="demo"></p>

  <script>

  function checkuser() 
  {
     var greeting;
         var userlog = '<%= Session["SessionKey"] %>';  // dreamweaver error here


     if (userlog==null)
          {
           greeting = "Bye";        // here - i will not show content
          } 
         else {
           greeting ="Go ahead";    // here - i will show content
          }
     document.getElementById("demo").innerHTML = greeting;
   }
   </script>
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
KillerMG
  • 3
  • 1

2 Answers2

1

You are checking if null that will never be true. If <%= Session["SessionKey"] %> was empty userlog will be set to an empty string and not null.

Try...

if (userlog == '')
Ballbin
  • 717
  • 6
  • 12
0

Use sessionStorage to check logged in User:

On Login Button:

if(typeof(Storage) !== "undefined") {
sessionStorage.setItem("Uname", "LoggedInUserName");
    }

and then:

function checkuser()
{
var user= sessionStorage.getItem("Uname");
if(user==null)
greeting="Bye"

else
{
  greeting="Go Ahead"
}
Dot_NET Pro
  • 2,095
  • 2
  • 21
  • 38