开发者

change PHP session id on link click

开发者 https://www.devze.com 2023-04-05 17:26 出处:网络
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 pa

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
        });
     });

});
0

精彩评论

暂无评论...
验证码 换一张
取 消