session_regenerate_id_cookie.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Test session_regenerate_id() function : basic functionality
  3. --SKIPIF--
  4. <?php
  5. include('skipif.inc');
  6. require __DIR__.'/../../../sapi/cgi/tests/include.inc';
  7. get_cgi_path() or die('skip no cgi');
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. * Prototype : bool session_regenerate_id([bool $delete_old_session])
  13. * Description : Update the current session id with a newly generated one
  14. * Source code : ext/session/session.c
  15. */
  16. echo "*** Testing session_regenerate_id() : basic functionality for cookie ***\n";
  17. require __DIR__.'/../../../sapi/cgi/tests/include.inc';
  18. $php = get_cgi_path();
  19. reset_env_vars();
  20. $file = dirname(__FILE__)."/session_regenerate_id_cookie.test.php";
  21. file_put_contents($file, '<?php
  22. ob_start();
  23. function find_cookie_header() {
  24. $headers = headers_list();
  25. $target = "Set-Cookie: PHPSESSID=";
  26. foreach ($headers as $h) {
  27. if (strstr($h, $target) !== FALSE) {
  28. echo $h."\n";
  29. return TRUE;
  30. }
  31. }
  32. var_dump($headers);
  33. return FALSE;
  34. }
  35. var_dump(session_start());
  36. var_dump(find_cookie_header());
  37. $id = session_id();
  38. var_dump(session_regenerate_id());
  39. var_dump(find_cookie_header());
  40. var_dump($id !== session_id());
  41. var_dump(session_id());
  42. var_dump(session_destroy());
  43. ob_end_flush();
  44. ?>');
  45. var_dump(`$php -n -d session.name=PHPSESSID $file`);
  46. unlink($file);
  47. echo "Done";
  48. ?>
  49. --EXPECTF--
  50. *** Testing session_regenerate_id() : basic functionality for cookie ***
  51. string(%d) "X-Powered-By: PHP/7.%s
  52. Expires: %s
  53. Cache-Control: no-store, no-cache, must-revalidate
  54. Pragma: no-cache
  55. Set-Cookie: PHPSESSID=%s; path=/
  56. Content-type: text/html; charset=UTF-8
  57. bool(true)
  58. Set-Cookie: PHPSESSID=%s; path=/
  59. bool(true)
  60. bool(true)
  61. Set-Cookie: PHPSESSID=%s; path=/
  62. bool(true)
  63. bool(true)
  64. string(32) "%s"
  65. bool(true)
  66. "
  67. Done