I've been trying to figure this out for a while now.
I'm using jquery ajax post to send form data using session variables on home.php to thankyou.php and then redirect the user (window.location.href='') to thankyou.php with the data from the form on home.php printed out on thankyou.php.
Also, the data that gets carried over to thankyou.php is emailed to the user.
I'm trying to do it this way so that the user will not see the query string at the end of thankyou.php.
Every time i test it out my session data doesn't carry over but when the email is sent, it has all the data.
Can someone tell me if im doing something wrong? Can jQuery pass session data to a php page?
Here is my code:
home.php
<?php
session_start();
?>
<script>
var formData = $('form').serialize();
$.post('thankyou.php', formData, function(){
$('form').submit();
window.location.href = '/thankyou.php;
});
</script>
thankyou.php
<?php
session_start();
$_SESSION['name'] = $_POST['name'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['phone'] = $_POST['phone'];
echo $_SESSION['name'];
echo $_SESSION['email'];
echo $_SESSION['phone'];
?>