Search code examples
phpformatted

session_start() not working in xampp


I created two files 1.php 2.php which are in the same folder(i am using xampp). In 1.php used session_start() and also used $_session['name']=abc. Then i opened 2.php to check whether session was created or not

2.php:

<?php

 if(isset($_session['name'])){

  echo $_session['name'];
 }
  else{
  echo "no session found!!";

  }
   ?>

and it keeps on saying "no session found!!"

Plz help ...

I searched a few sites n they say that by default d session is for whole folder containing d script and session_set_cookie_params($lifetime,'/') (where $lifetime=60*60) is also nt helping. On d other hand if at d end of1.php i use require("2.php") then abc is displayed.


Solution

  • What you have done is right in 1.php, however, 2.php must start the session before using it.

    2.php

    <?php
     session_start();
     if(isset($_SESSION['name'])) {
        echo $_SESSION['name'];
     }
     else{
         echo "no session found!!";
     }
    ?>