PHP session working on localhost but not on hosting server

6 replies
Hello,
I have my website working well on localhost. I have 5 page website. Now On start of each page I write the below code to check if the session exists or not. And if it is I put logout button otherwise login button at one place

Code:
<?php session_start();
$chkvar=0;
if(isset($_SESSION['uid']))
{
$chkvar=1;
}
?>
After this my html tag and code starts. However this working well on my localhost. I am using wamp server. But when I login to server and goto any page and check the value of $chkvar, its always 0.

So what should I do.? Please let me know if you require more information.

Thanks
#hosting #localhost #php #server #session #working
  • Profile picture of the author Bruce Wayne
    Are you sure you set $_SESSION['uid'] variable? The other problem may be that your session expires too fast on another server. Did you configure the hosting server for yourself? Did you try to check your code on other servers (excluding localhost server)?
    {{ DiscussionBoard.errors[6986714].message }}
  • Profile picture of the author sethczerepak
    I'm with Mr. Wayne on this, start by making sure you're setting the session variable correctly. Would def help to see that code.
    {{ DiscussionBoard.errors[6987237].message }}
    • Profile picture of the author Brandon Tanner
      If you're sure that you've set your session variable correctly, and it still doesn't work... then it's possible that sessions either aren't enabled or aren't configured correctly in the php.ini file on your server.

      How do you enable PHP sessions
      Signature

      {{ DiscussionBoard.errors[6987356].message }}
  • Profile picture of the author lordspace
    you probably have some empty space either before the opening php tag
    <?php
    or after the closing one
    ?>
    All of these things can break the cookies that handle the session.

    you can try putting this in front of the file to see any errors.

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    Signature

    Are you using WordPress? Have you tried qSandbox yet?

    {{ DiscussionBoard.errors[6987491].message }}
  • Profile picture of the author mesmsgs
    Maybe on you localhost the name for php session id is "uid" but not on your remote server ?!
    {{ DiscussionBoard.errors[7075775].message }}
  • Profile picture of the author smoothseo
    You should check with the server configuration, code looks perfect if it works on localhost it should work on server too
    {{ DiscussionBoard.errors[7084209].message }}

Trending Topics