I am trying to create an HTML link that changes the PHP 开发者_JS百科session id. Basically I need to call the session_regenerate_id(); when a link is clicked. The problem is that it can't run on the page that I am linking to. There is an upload form that reloads after upload so the function cannot be on the page I am linking to.
Can I do an AJAX post to a separate PHP file?
In your php file called regenerate.php:
<?php session_regenerate_id(); ?>
And then with jquery.
$.POST('url/to/regenerate.php', function() {
// callback
});
Then to run it:
$(function() {
$('#postNew').click(function(e) {
e.preventDefault(); // stops the link from going anywhere
$.POST('url/to/regenerate.php', function() {
// callback
});
});
});
精彩评论