-1

I have set $_SESSION['admin']=1 after login form validation.
After that the page was redirect and check $_SESSION['admin'] value and load contents.
It was worked fine in local. But it can't in online linux server. Any help..?

admin.php

<?php
   session_start();
   $admin = 0;
   if(isset($_SESSION['admin'])){
      $admin = $_SESSION['admin'];
   }
   if($admin == 0){
?>
<form action="" class="login">
     <label>User Name :</label>
     <input type="text" class="uname"/>
     <label>Password :</label>
     <input type="password" class="pwd"/>
     <input type="submit" class="lSubmit" value="SUBMIT"/>
     <p class="alert lAlert">test alert</p>
</form>
<?php }elseif($admin == 1){ ?>
     <h1>Welcome Site Admin..!!</h1>
<?php } ?>

JQuery

$('.lSubmit').click(function(){
    var name = $('.uname').val();
    var pwd = $('.pwd').val();
    $.post("validation/login.php",{name:name,pwd:pwd}).success(function(data){
        var obj = jQuery.parseJSON(data);
        if(obj.success == 1){
            $('.alert').css('color','#067800');
            window.location = "/admin.php";
        }else{
            $('.alert').css('color','#CC0000');
        }
        $('.lAlert').text(obj.msg);
        $('.lAlert').fadeIn('slow');
    });
    return false;
});

validation/login.php

<?php
 session_start();
 $name = $_POST['name'];
 $pwd = $_POST['pwd'];
 $err['success'] = 0;
 $err['msg'] = '';
 if($name == ''){
  $err['msg'] = 'Name required';
 }else if($pwd == ''){
  $err['msg'] = 'Password required';
 }else if($name != 'admin'){
  $err['msg'] = 'Wrong username';
 }else if($pwd != 'admin'){
      $err['msg'] = 'Wrong password';
 }else{
  $err['msg'] = 'Success';
  $err['success'] = 1;
  $_SESSION['admin'] = 1;
 }
 echo json_encode($err);
?>

When I run this , it was successfully made validation and if username and password is admin then it shows Success in alert. But after it was redirected and again the form only loaded in online server. But in local the welcome text was loaded. But in other pages in online the session works fine. Can anybody help me?

Vinu
  • 167
  • 4
  • 14
  • many things might be wrong, check everything from web server/modules/php.ini – Gntem Jul 28 '12 at 06:31
  • @GeoPhoenix The session works fine for other pages.. But problem was $_SESSION['admin'] variable only.It was not able to set – Vinu Jul 28 '12 at 06:34
  • 1
    We'll need more information than "it doesn't work". Did you get an error of some sort? What testing and debugging have you done? We don't have access to your stuff, so we can only work with what you've already done. If you've conducted some tests, we can interpret the results; but if you just tell us "it doesn't work", we have no idea where to go for answers. – Palladium Jul 28 '12 at 06:44
  • Answered here http://stackoverflow.com/a/11700712/970721 – Vitalii Zurian Jul 28 '12 at 11:44

2 Answers2

0

My only guess would be that usually session starts automatically with most development kits like xampp

On real servers most of the time you have to start it manually with session_start()

Opi
  • 1,288
  • 1
  • 10
  • 14
0

add

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

at the start of your script and check any errors and post back. My guess is is that you have some permissions problem on the server.

Vlad Balmos
  • 3,372
  • 19
  • 34