似乎无法传递POST的SESSION变量

Sorry if this is a duplicate, but I really cant find anything that could solve my problem. I can pass numbers and strings like $_SESSION['blabla']="123'; but I can't pass this $_POST value from the textfield and submit button.

Page 1 (sessions.php)

<?php session_start(); ?>

!doctype stuff here

<body>
<form id="form1" name="form1" method="post"  action="sessions2.php">
  <label>
    <input type="text" name="damn" id="damn" />
    <input type="submit" name="submit" id="submit" value="Submit" />

  </label>
</form>

<?php

$omg = $_POST['damn'];

$_SESSION['damn'] = $omg;
echo $_SESSION['damn'] ;


?>

Page 2 (sessions2.php)

<?php
session_start();
$fires = $_SESSION['damn'];
echo "wth";
echo $_SESSION['damn'];
?>

PS. Sorry for the names.. I'm truly stumped.

In sessions2.php

// you POST "damn" variable via form, using post method, so:
$fires = $_POST['damn'];
// and:
$_SESSION['damn'] = $fier;
// or 
$_SESSION['damn'] = $_POST['damn'];

PHP code in file sessions.php doesn't work, because in form action you have session2.php.

You need to put the code that reads from $_POST in the file that you submit the form to.

Currently your process is:

  1. Get request for sessions.php
  2. Send form to browser
  3. Assign $_POST['damn'] (which is undefined) to the session.
  4. User submits form
  5. Get request for sessions2.php
  6. Ignore $_POST (which is now populated)
  7. Read from the session (where the variable is still undefined).

damn is populated in the form submission request (step 4/5) not the request where you are trying to read it (step 1).