Q:

two php script using ajax is no session

In a.php, i start the session, and i use ajax to post data to b.php. 
in b.php, if have session, is find, if no session, do nothing. 
but i always to read the session is NULL, i need to check user validity or security reason.
How to solve it?

the return always NULL

a.php
 <?php
session_start();
$_SESSION['userid'] = '1123';
$_SESSION['username'] = 'henry';
if($_SESSION['userid']) { 
?>
 <script>
$("button#Search").click(function(e){
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "b.php",
            data: {
                search: $("input#search").val()
            },
            success: function(response){
                $("#message").html(response);
            },
            error: function(){
                console.log("error");
                return e.defaultPrevented || e.returnValue == false;
            }
        });
    });
 </script>
 <?php } ?>

b.php
 <?php
if($_SESSION['userid']) {
  echo "success";
} else {
  var_dump($_SESSION);
}
?>

A:

You also need to add start session in b.php
session_start();
if($_SESSION['userid']) {
  echo "success";
} else {
  var_dump($_SESSION);
}

