I'm trying to pass a token to the SESSION like this, in the index.php file:
Code: Select all
session_start();
$_SESSION['token'] = sha1(mt_rand(100, 10000));Code: Select all
var the_token = '<?php echo $_SESSION['token']; ?>';
// jQuery Post
$("element").click(function() {
$.post('ajax_io.php', {
token: the_token
}, function(response) {
// Do something with response
});
Code: Select all
session_start();
if($_REQUEST['token'] != $_SESSION['token']) die("Horribly!");I should also mention at this point that the index.php has a Foreach loop that loops 3 times to display the tabbed interface.
Code: Select all
<?php
// pseudo-code
foreach(expression) : ?>
<div class="tab"><?php echo $data['html_string']; ?></div>
<?php endforeach; ?>Any idea why would an echo statement, withing a foreach loop, trigger the 2nd line of script ($_SESSION['token'] = sha1(mt_rand(100, 10000));) again?
UPDATE:
Fixed a typo, was multitasking at the time and mixed up the loop types. It was a foreach loop and not a while loop!