Question

doesn't work php session

  • Posted January 8, 2015
  • 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.

Subscribe
Share

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();
?>

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.

That’s not the problem. I don’t read session.

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


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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