mysql - PHP Session variable checking is not working -


Here is my issue that I am big in PHP. I have made a login page and it works perfectly in my local machine But after uploading to the server it is not working.

The session has been created but the redirection is not happening.

Here is my code and any help is really appreciated.

  if (isset ($ _ POST ['btn-login'])) {$ username = $ _POST ['username']; $ Password = $ _POST ['password']; Include 'Connection.php'; $ Sql ​​= "Choose * from where the user name = '$ user name' and password = sha1 ('$ password') and status = '1'"; $ Result = mysql_query ($ sql); $ Result = mysql_fetch_array ($ result); $ UserId = ''; If ($ result) {$ userId = $ result ['id']; $ _SESSION ['userId'] = $ user ID; If ($ userId == 1) {header ("location: map.php"); } And if ($ userId == 2) {header ("location: admin / map-settings.php"); } Else {echo "
  • There is an error in the login Please contact administrator & lt; / li & gt;"; }} And {echo "
  • Invalid user name or password ";

    Ensure that print_r ($ _ session)

    If this does not give an empty array, then your session is set.

    Now make sure that nothing in your code started before you set the "Location" header in your code and you can use it to redirect your page

      if (! Heads_saint ()) $ filename = "map.php"; Header ('location:'. $ File name); Else {echo & lt; Script type = "text / javascript" & gt; '; Echo 'window.location.href = "'. $ Filename. ''; '; Echo & lt; / script'; 'echo & lt; noscript'; echo '& lt; meta http-equiv = "Refresh" content = "0; Url = '. $ Filename '' /> '; Echo & lt; / noscript & gt;';}    

  • Comments

    Popular posts from this blog

    ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

    Matlab transpose a table vector -

    c# - Textbox not clickable but editable -