I am trying to send POST data into a SESSION variable
$_SESSION['plan'] = $_POST['plan']
info.php show that sessions are loaded. browser -> inspect element appears to show sessions initialized but no key => values.
But I cannot get the session value to display. no errors in apache logs.
main dynamic frame:
cat index.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="index,follow"/>
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<nav class="nav">
<ul>
BLAH
</ul>
</nav>
<div id="content">
<?php
$pages_dir = 'pages';
if (!empty($_GET['p'])) {
$pages = scandir($pages_dir, 0);
unset($pages[0], $pages[1]);
$p=$_GET['p'];
if(in_array($p.'.inc.php', $pages)){
include($pages_dir.'/'.$p.'.inc.php');
}else {
echo 'Sorry, page not found.';
}
}else{
include($pages_dir.'/home.inc.php');
}
?>
</div>
</body>
</html>
User form page:
cat pages/payment.inc.php
<?php
//$_SESSION['plan'] = $_POST['plan'];
?>
<div id="content_pay">
<form action="pages/scheckout.php" method="post">
<div>
<input type="radio" id="plan1" name="plan" value="2500"> Beta membership <br><br>
<input type="radio" id="plan2" name="plan" value="3500"> VIP membership <br><br>
<label for="plan"> If you would like to pay another amount, enter the amount here:</label>
<input type="text" id="plan3" name="plan" />
<br>
<label for="invoice_num"> Enter the invoice number here:</label>
<input type="text" name="invoice_num" /> <br>
<input type="submit" value="submit" name="submit">
</div>
</form>
</div>
Basically this page is here just to capture the POST and assign it to SESSION then redirect with SESSION loaded:
cat pages/scheckout.php
<?php
session_start();
$_SESSION['plan'] = $_POST['plan'];
//needed to prevent weird race conditions
session_write_close();
header("location: ../index.php?p=scheckout");
die();
echo "<br>";
echo $_SESSION['plan'];
?>
Where is goes to:
cat pages/scheckout.inc.php
<?php
require_once('pages/sconfig.php');
?>
<div id="content_pay">
<form action="pages/scharge.php" method="post">
<div>
<script src="http://ift.tt/1doUtf9" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
myElem.setAttribute('data-amount', <?php $_SESSION['plan']; ?>);
myElem.setAttribute('data-description', <?php $_SESSION['plan']; ?>); >
</script>
</div>
</form>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<?php
echo $_SESSION['plan'];
?>
How do I get SESSIONS loaded from POST to display?
Aucun commentaire:
Enregistrer un commentaire