Saxtmey
By:
Saxtmey

doesn't work php session

January 8, 2015 3.1k views
PHP
<?php 
session_start();

$_SESSION["name"] = "sami"; 
echo $_SESSION["name"]; 
?>

then;

<?php 
session_start();

echo $_SESSION["name"]; 
?>

session write but session doesn't read.

chmod 777 /var/php5/sess*

but it doesn't work.

4 comments
  • Did the comment formatter eat up the underscore in the first block? In other words, were you expecting $SESSION["name"] equal to $_SESSION["name"] ?

  • That's not the problem. I don't read session.

  • If you really had an underscore in both files, then you most likely tried to run the files at the command line, which you can't store the serialized values from your pages into a cookie. Only the web browser provides that, unless there's some magic new php.ini variable I missed.

  • Let's clean this up a bit.

    In file1.php, add this:

    <?php
    session_start();
    $_SESSION['name'] = "sami";
    header("location:file2.php");
    exit();
    ?>
    

    In file2.php

    <?php
    session_start();
    echo "Your \$_SESSION['name'] var is ".$_SESSION['name'];
    exit();
    ?>
    
1 Answer

This question was answered by @JonsJava:

Let's clean this up a bit.

In file1.php, add this:

<?php
session_start();
$_SESSION['name'] = "sami";
header("location:file2.php");
exit();
?>

In file2.php

<?php
session_start();
echo "Your \$_SESSION['name'] var is ".$_SESSION['name'];
exit();
?>

View the original comment

Have another answer? Share your knowledge.