0

page1.php

$for = $_GET['name'];
session_start();
$_SESSION['new'] = $for;
session_write_close();
header('Location: http://newwebsite.com);

page2.php

<?php
$new = '';
session_start();
$new = $_SESSION['new'];

?>

<script>  
    $(document).ready(function()
    {    
        <?php if($new != '') { ?>
        var banner = document.getElementById("A");
        var hiddenInput = document.getElementById("B");
        banner.innerHTML = <?php echo "'".$new."'" ?>;
        hiddenInput.value = <?php echo "'".$new."'" ?>;
        <?php }

        if(session_destroy())
        {
            unset($_SESSION['new']);
        }
        ?>
    });
</script>

I get my data from page1.php but when it never seems to get cleared.

If I do

print_r($_SESSION); 

It results in empty output, but next time I come to the page with a different variable from page1.php it still shows me the older variable. What can I do?

Lagoo87
  • 621
  • 1
  • 6
  • 20
  • The PHP code *does not* run *in* the JavaScript handler.. the formatting looks "suspicious" at best. – user2864740 Feb 10 '15 at 19:18
  • you need use more soap to wash then. –  Feb 10 '15 at 19:24
  • I don't know what you're saying @user2864740 - I changed some vars to post here. It works in my code. I need to know what the issue is with the variable not being unset.. or appearing unset by the data not cleared? – Lagoo87 Feb 10 '15 at 19:28
  • 1
    Why bother with `session_destroy()`? Just `unset` the variable – Machavity Feb 10 '15 at 19:31
  • @Machavity When I go to page1 and send- it goes to page 2 and displays as normal. If I go back and go through the same process (with a different selection) it shows the the first result again. With destroy or unset, or both. – Lagoo87 Feb 10 '15 at 19:35
  • Cache problem http://stackoverflow.com/questions/1971721/how-to-use-http-cache-headers-with-php – Drifter Feb 10 '15 at 19:46

0 Answers0