当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Cookie will not set/output to future page

问题描述:

I cannot get the cookie to output on the page 'images.php'. I have got cookies working in other areas of my site but I cannot get it to work here. My form uses an AJAX submit which passes the data to a PHP file and then if there are no errors in that file redirects the user to the next step in the process.

HTML Input field

<input type="text" name="price" class="form-control" placeholder="Enter the price you wish to list your item for" />

AJAX Submit

<script type="text/javascript">

$('form.ajax').on('submit', function () {

var that= $(this),

url = 'inc/admin/validate_sell.php',

type = that.attr('method'),

data = {};

that.find('[name]').each(function(index, value) {

var that = $(this),

name = that.attr('name'),

value = that.val();

data[name] = value;

});

$.ajax({

url: url,

type: type,

data: data,

success: function(data) {

$("#responce").html(data);

}

});

return false;

});

</script>

PHP

setcookie('price', $_POST['price'], time()+3600);

echo '<script>window.location.replace("http://localhost/ur/images.php")</script>';

Future page which cookies should be echoed out on (images.php).

<?php echo $_COOKIE['price']; ?>

However this returns no value on 'images.php'.

分享给朋友:
您可能感兴趣的文章:
随机阅读: