1

So, I looked through different posts and other resources and I still cannot make it work. Seems basic and common but I am lost. Here is my code. Page "test_start.php":

<html>
<head>
<title>Test</title>
</head>
<body>
    <p>Click <a href="test_script.php">here</a></p>
</body>
</html>

Page "test_script.php":

<?php
    session_start();
    $_SESSION['passed']="My text!";
    header("Location: test_ultima.php");
?>

Page "test_ultima.php":

<?php session_start(); ?>
<html>
<head>
    <title>Something</title>
</head>
<body>
    <p>This text shows, so redirect worked!</p>
    <?php
        echo "<p>Result isset: ".isset($_SESSION['passed'])."</p>";
        echo "<p>I passed:".$_SESSION['passed']."</p>";
    ?>
</body>
</html>

When I click on the link I see the following:

This text shows, so redirect worked!
Result isset:
I passed:

What am I doing wrong? Please, if you can, also explein why and how it shall work...

Added Note: The first file is .php because in the end it will contain also some php code... this is obviously an example to first make it work and understand how it works...

rodedo
  • 791
  • 4
  • 10
  • 23
  • Have you enabled error reporting in PHP? – PeeHaa Jun 03 '12 at 13:20
  • My php is pretty much in the "default" settings, is it enabled by default? If not, how shall I enable it? – rodedo Jun 03 '12 at 13:21
  • put print_r($_SESSION) on the second page to view the content – codingbiz Jun 03 '12 at 13:26
  • print_r returns: "Array ( ) " – rodedo Jun 03 '12 at 13:30
  • Add this on top of all php files: `error_reporting(E_ALL | E_STRICT); ini_set("display_errors", 1);` – PeeHaa Jun 03 '12 at 13:33
  • @RepWhoringPeeHaa thanks for helping out showing errors... with the error reporting I get: `Warning: session_start() [function.session-start]: open(C:\PHP\sessions\sess_87ruc3n1gb0e5ivlsfurgr0nr0, O_RDWR) failed: No such file or directory (2) in C:\Inetpub\wwwroot\missione-berna.ch\test_ultima.php on line 3` which tells me the session_start is not managing to do his job... does it mean there is something wrong in my php installation? – rodedo Jun 03 '12 at 13:45

1 Answers1

1

From the comment by OP:

session_start() [function.session-start]: open(C:\PHP\sessions\sess_87ruc3n1gb0e5ivlsfurgr0nr0, O_RDWR) failed: No such file or directory (2) in C:\Inetpub\wwwroot\missione-berna.ch\test_ultima.php on line 3

This means that either the directory to which PHP tries to write the sessions doesn't exist or it just doesn't have the permission to read/write in this directory.

So you first need to check out whether the directory actually exists. If it exists you should check the permissions of the apache (or other webservice) user on that directory.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
  • 1
    So the issue was in my php installation set up, the php.ini pointed to the folder "sessions" but the folder name was mispelled (session). Thanks to all it was instructive! – rodedo Jun 03 '12 at 13:52
  • Let this be a lesson to you. **Always** enable error reporting when you are developing. :-) – PeeHaa Jun 03 '12 at 14:02