session_basic3.phpt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. --TEST--
  2. Test basic function : variation3 use_trans_sid
  3. --INI--
  4. session.use_strict_mode=0
  5. session.use_only_cookies=0
  6. session.use_trans_sid=1
  7. session.save_handler=files
  8. session.hash_bits_per_character=4
  9. session.hash_function=0
  10. session.gc_probability=1
  11. session.gc_divisor=1000
  12. session.gc_maxlifetime=300
  13. session.save_path=
  14. session.name=PHPSESSID
  15. url_rewriter.hosts=
  16. --SKIPIF--
  17. <?php include('skipif.inc'); ?>
  18. --FILE--
  19. <?php
  20. ob_start();
  21. /*
  22. * Prototype : session.use_trans_sid=1
  23. * Description : Test basic functionality.
  24. * Source code : ext/session/session.c
  25. */
  26. echo "*** Testing basic session functionality : variation3 use_trans_sid ***\n";
  27. /*
  28. echo "*** test output_add_rewrite_var() ***\n";
  29. output_add_rewrite_var('var', 'value');
  30. echo '
  31. <a href="/">test</a>
  32. <a href="/#bar">test</a>
  33. <a href="/?foo">test</a>
  34. <a href="/?foo#bar">test</a>
  35. <a href="/?foo=var">test</a>
  36. <a href="/?foo=var#bar">test</a>
  37. <a href="file.php">test</a>
  38. <a href="file.php?foo">test</a>
  39. <a href="file.php?foo=var">test</a>
  40. <a href="http://php.net">test</a>
  41. <a href="http://php.net/">test</a>
  42. <a href="http://php.net/#bar">test</a>
  43. <a href="http://php.net/?foo">test</a>
  44. <a href="http://php.net/?foo#bar">test</a>
  45. <a href="http://php.net/?foo=var">test</a>
  46. <a href="http://php.net/?foo=var#bar">test</a>
  47. <a href="http://php.net/file.php">test</a>
  48. <a href="http://php.net/file.php#bar">test</a>
  49. <a href="http://php.net/file.php?foo">test</a>
  50. <a href="http://php.net/file.php?foo#bar">test</a>
  51. <a href="http://php.net/file.php?foo=var">test</a>
  52. <a href="http://php.net/file.php?foo=var#bar">test</a>
  53. <a href="http://php.net/some/path/file.php">test</a>
  54. <a href="http://php.net/some/path/file.php?foo">test</a>
  55. <a href="http://php.net/some/path/file.php?foo=var">test</a>
  56. <a href="http://php.net/some/path/file.php?foo=var#bar">test</a>
  57. <a href="https://php.net">test</a>
  58. <a href="https://php.net/">test</a>
  59. <a href="https://php.net/?foo=var#bar">test</a>
  60. <a href="https://php.net/file.php">test</a>
  61. <a href="https://php.net/file.php?foo=var#bar">test</a>
  62. <a href="https://php.net/some/path/file.php">test</a>
  63. <a href="https://php.net/some/path/file.php?foo=var#bar">test</a>
  64. <a href="https://php.net:8443">test</a>
  65. <a href="https://php.net:8443/">test</a>
  66. <a href="https://php.net:8443/?foo=var#bar">test</a>
  67. <a href="https://php.net:8443/file.php">test</a>
  68. <a href="https://php.net:8443/file.php?foo=var#bar">test</a>
  69. <a href="https://php.net:8443/some/path/file.php">test</a>
  70. <a href="https://php.net:8443/some/path/file.php?foo=var#bar">test</a>
  71. <a href="//php.net">test</a>
  72. <a href="//php.net/">test</a>
  73. <a href="//php.net/#bar">test</a>
  74. <a href="//php.net/?foo">test</a>
  75. <a href="//php.net/?foo#bar">test</a>
  76. <a href="//php.net/?foo=var">test</a>
  77. <a href="//php.net/?foo=var#bar">test</a>
  78. <a href="//php.net/file.php">test</a>
  79. <a href="//php.net/file.php#bar">test</a>
  80. <a href="//php.net/file.php?foo">test</a>
  81. <a href="//php.net/file.php?foo#bar">test</a>
  82. <a href="//php.net/file.php?foo=var">test</a>
  83. <a href="//php.net/file.php?foo=var#bar">test</a>
  84. <a href="//php.net/some/path/file.php">test</a>
  85. <a href="//php.net/some/path/file.php?foo">test</a>
  86. <a href="//php.net/some/path/file.php?foo=var">test</a>
  87. <a href="//php.net/some/path/file.php?foo=var#bar">test</a>
  88. <form action="script.php" method="post">
  89. <input type="text" name="test1"></input>
  90. <input type="text" name="test2" />
  91. </form>
  92. ';
  93. output_reset_rewrite_vars();
  94. */
  95. echo "*** Test trans sid ***\n";
  96. ob_start();
  97. $session_id = 'testid';
  98. session_id($session_id);
  99. session_start();
  100. // Should add session ID to relative URL only for SECURITY
  101. echo '
  102. <a href="/">test</a>
  103. <a href="/path">test</a>
  104. <a href="/path/">test</a>
  105. <a href="/path/?foo=var">test</a>
  106. <a href="../">test</a>
  107. <a href="../path">test</a>
  108. <a href="../path/">test</a>
  109. <a href="../path/?foo=var">test</a>
  110. <a href="/#bar">test</a>
  111. <a href="/path/#bar">test</a>
  112. <a href="/path/?foo=var#bar">test</a>
  113. <a href="../#bar">test</a>
  114. <a href="../path/#bar">test</a>
  115. <a href="../path/?foo=var#bar">test</a>
  116. <a href="/?foo">test</a>
  117. <a href="/?foo#bar">test</a>
  118. <a href="/?foo=var">test</a>
  119. <a href="/?foo=var#bar">test</a>
  120. <a href="../?foo">test</a>
  121. <a href="../?foo#bar">test</a>
  122. <a href="../?foo=var">test</a>
  123. <a href="../?foo=var#bar">test</a>
  124. <a href="file.php">test</a>
  125. <a href="file.php?foo">test</a>
  126. <a href="file.php?foo=var">test</a>
  127. <a href="file.php?foo=var#bar">test</a>
  128. <a href="../file.php">test</a>
  129. <a href="../file.php?foo">test</a>
  130. <a href="../file.php?foo=var">test</a>
  131. <a href="../file.php?foo=var#bar">test</a>
  132. <a href="http://php.net">test</a>
  133. <a href="http://php.net/">test</a>
  134. <a href="http://php.net/#bar">test</a>
  135. <a href="http://php.net/?foo">test</a>
  136. <a href="http://php.net/?foo#bar">test</a>
  137. <a href="http://php.net/?foo=var">test</a>
  138. <a href="http://php.net/?foo=var#bar">test</a>
  139. <a href="http://php.net/file.php">test</a>
  140. <a href="http://php.net/file.php#bar">test</a>
  141. <a href="http://php.net/file.php?foo">test</a>
  142. <a href="http://php.net/file.php?foo#bar">test</a>
  143. <a href="http://php.net/file.php?foo=var">test</a>
  144. <a href="http://php.net/file.php?foo=var#bar">test</a>
  145. <a href="http://php.net/some/path/file.php">test</a>
  146. <a href="http://php.net/some/path/file.php?foo">test</a>
  147. <a href="http://php.net/some/path/file.php?foo=var">test</a>
  148. <a href="http://php.net/some/path/file.php?foo=var#bar">test</a>
  149. <a href="https://php.net">test</a>
  150. <a href="https://php.net/">test</a>
  151. <a href="https://php.net/?foo=var#bar">test</a>
  152. <a href="https://php.net/file.php">test</a>
  153. <a href="https://php.net/file.php?foo=var#bar">test</a>
  154. <a href="https://php.net/some/path/file.php">test</a>
  155. <a href="https://php.net/some/path/file.php?foo=var#bar">test</a>
  156. <a href="https://php.net:8443">test</a>
  157. <a href="https://php.net:8443/">test</a>
  158. <a href="https://php.net:8443/?foo=var#bar">test</a>
  159. <a href="https://php.net:8443/file.php">test</a>
  160. <a href="https://php.net:8443/file.php?foo=var#bar">test</a>
  161. <a href="https://php.net:8443/some/path/file.php">test</a>
  162. <a href="https://php.net:8443/some/path/file.php?foo=var#bar">test</a>
  163. <a href="//php.net">test</a>
  164. <a href="//php.net/">test</a>
  165. <a href="//php.net/#bar">test</a>
  166. <a href="//php.net/?foo">test</a>
  167. <a href="//php.net/?foo#bar">test</a>
  168. <a href="//php.net/?foo=var">test</a>
  169. <a href="//php.net/?foo=var#bar">test</a>
  170. <a href="//php.net/file.php">test</a>
  171. <a href="//php.net/file.php#bar">test</a>
  172. <a href="//php.net/file.php?foo">test</a>
  173. <a href="//php.net/file.php?foo#bar">test</a>
  174. <a href="//php.net/file.php?foo=var">test</a>
  175. <a href="//php.net/file.php?foo=var#bar">test</a>
  176. <a href="//php.net/some/path/file.php">test</a>
  177. <a href="//php.net/some/path/file.php?foo">test</a>
  178. <a href="//php.net/some/path/file.php?foo=var">test</a>
  179. <a href="//php.net/some/path/file.php?foo=var#bar">test</a>
  180. <form action="script.php" method="post">
  181. <input type="text" name="test1"></input>
  182. <input type="text" name="test2" />
  183. </form>
  184. <form action="../script.php" method="post">
  185. <input type="text" name="test1"></input>
  186. <input type="text" name="test2" />
  187. </form>
  188. <form action="/path/script.php" method="post">
  189. <input type="text" name="test1"></input>
  190. <input type="text" name="test2" />
  191. </form>
  192. <form action="../path/script.php" method="post">
  193. <input type="text" name="test1"></input>
  194. <input type="text" name="test2" />
  195. </form>
  196. <form method="post" action="http://php.net/script.php">
  197. <input type="text" name="test1"></input>
  198. <input type="text" name="test2" />
  199. </form>
  200. <form method="post" action="https://php.net/script.php">
  201. <input type="text" name="test1"></input>
  202. <input type="text" name="test2" />
  203. </form>
  204. <form method="post" action="//php.net/script.php">
  205. <input type="text" name="test1"></input>
  206. <input type="text" name="test2" />
  207. </form>
  208. ';
  209. var_dump(session_commit());
  210. echo "*** Cleanup ***\n";
  211. var_dump(session_start());
  212. var_dump(session_id());
  213. var_dump(session_destroy());
  214. ob_end_flush();
  215. ?>
  216. --EXPECT--
  217. *** Testing basic session functionality : variation3 use_trans_sid ***
  218. *** Test trans sid ***
  219. <a href="/?PHPSESSID=testid">test</a>
  220. <a href="/path?PHPSESSID=testid">test</a>
  221. <a href="/path/?PHPSESSID=testid">test</a>
  222. <a href="/path/?foo=var&PHPSESSID=testid">test</a>
  223. <a href="../?PHPSESSID=testid">test</a>
  224. <a href="../path?PHPSESSID=testid">test</a>
  225. <a href="../path/?PHPSESSID=testid">test</a>
  226. <a href="../path/?foo=var&PHPSESSID=testid">test</a>
  227. <a href="/?PHPSESSID=testid#bar">test</a>
  228. <a href="/path/?PHPSESSID=testid#bar">test</a>
  229. <a href="/path/?foo=var&PHPSESSID=testid#bar">test</a>
  230. <a href="../?PHPSESSID=testid#bar">test</a>
  231. <a href="../path/?PHPSESSID=testid#bar">test</a>
  232. <a href="../path/?foo=var&PHPSESSID=testid#bar">test</a>
  233. <a href="/?foo&PHPSESSID=testid">test</a>
  234. <a href="/?foo&PHPSESSID=testid#bar">test</a>
  235. <a href="/?foo=var&PHPSESSID=testid">test</a>
  236. <a href="/?foo=var&PHPSESSID=testid#bar">test</a>
  237. <a href="../?foo&PHPSESSID=testid">test</a>
  238. <a href="../?foo&PHPSESSID=testid#bar">test</a>
  239. <a href="../?foo=var&PHPSESSID=testid">test</a>
  240. <a href="../?foo=var&PHPSESSID=testid#bar">test</a>
  241. <a href="file.php?PHPSESSID=testid">test</a>
  242. <a href="file.php?foo&PHPSESSID=testid">test</a>
  243. <a href="file.php?foo=var&PHPSESSID=testid">test</a>
  244. <a href="file.php?foo=var&PHPSESSID=testid#bar">test</a>
  245. <a href="../file.php?PHPSESSID=testid">test</a>
  246. <a href="../file.php?foo&PHPSESSID=testid">test</a>
  247. <a href="../file.php?foo=var&PHPSESSID=testid">test</a>
  248. <a href="../file.php?foo=var&PHPSESSID=testid#bar">test</a>
  249. <a href="http://php.net">test</a>
  250. <a href="http://php.net/">test</a>
  251. <a href="http://php.net/#bar">test</a>
  252. <a href="http://php.net/?foo">test</a>
  253. <a href="http://php.net/?foo#bar">test</a>
  254. <a href="http://php.net/?foo=var">test</a>
  255. <a href="http://php.net/?foo=var#bar">test</a>
  256. <a href="http://php.net/file.php">test</a>
  257. <a href="http://php.net/file.php#bar">test</a>
  258. <a href="http://php.net/file.php?foo">test</a>
  259. <a href="http://php.net/file.php?foo#bar">test</a>
  260. <a href="http://php.net/file.php?foo=var">test</a>
  261. <a href="http://php.net/file.php?foo=var#bar">test</a>
  262. <a href="http://php.net/some/path/file.php">test</a>
  263. <a href="http://php.net/some/path/file.php?foo">test</a>
  264. <a href="http://php.net/some/path/file.php?foo=var">test</a>
  265. <a href="http://php.net/some/path/file.php?foo=var#bar">test</a>
  266. <a href="https://php.net">test</a>
  267. <a href="https://php.net/">test</a>
  268. <a href="https://php.net/?foo=var#bar">test</a>
  269. <a href="https://php.net/file.php">test</a>
  270. <a href="https://php.net/file.php?foo=var#bar">test</a>
  271. <a href="https://php.net/some/path/file.php">test</a>
  272. <a href="https://php.net/some/path/file.php?foo=var#bar">test</a>
  273. <a href="https://php.net:8443">test</a>
  274. <a href="https://php.net:8443/">test</a>
  275. <a href="https://php.net:8443/?foo=var#bar">test</a>
  276. <a href="https://php.net:8443/file.php">test</a>
  277. <a href="https://php.net:8443/file.php?foo=var#bar">test</a>
  278. <a href="https://php.net:8443/some/path/file.php">test</a>
  279. <a href="https://php.net:8443/some/path/file.php?foo=var#bar">test</a>
  280. <a href="//php.net">test</a>
  281. <a href="//php.net/">test</a>
  282. <a href="//php.net/#bar">test</a>
  283. <a href="//php.net/?foo">test</a>
  284. <a href="//php.net/?foo#bar">test</a>
  285. <a href="//php.net/?foo=var">test</a>
  286. <a href="//php.net/?foo=var#bar">test</a>
  287. <a href="//php.net/file.php">test</a>
  288. <a href="//php.net/file.php#bar">test</a>
  289. <a href="//php.net/file.php?foo">test</a>
  290. <a href="//php.net/file.php?foo#bar">test</a>
  291. <a href="//php.net/file.php?foo=var">test</a>
  292. <a href="//php.net/file.php?foo=var#bar">test</a>
  293. <a href="//php.net/some/path/file.php">test</a>
  294. <a href="//php.net/some/path/file.php?foo">test</a>
  295. <a href="//php.net/some/path/file.php?foo=var">test</a>
  296. <a href="//php.net/some/path/file.php?foo=var#bar">test</a>
  297. <form action="script.php" method="post"><input type="hidden" name="PHPSESSID" value="testid" />
  298. <input type="text" name="test1"></input>
  299. <input type="text" name="test2" />
  300. </form>
  301. <form action="../script.php" method="post"><input type="hidden" name="PHPSESSID" value="testid" />
  302. <input type="text" name="test1"></input>
  303. <input type="text" name="test2" />
  304. </form>
  305. <form action="/path/script.php" method="post"><input type="hidden" name="PHPSESSID" value="testid" />
  306. <input type="text" name="test1"></input>
  307. <input type="text" name="test2" />
  308. </form>
  309. <form action="../path/script.php" method="post"><input type="hidden" name="PHPSESSID" value="testid" />
  310. <input type="text" name="test1"></input>
  311. <input type="text" name="test2" />
  312. </form>
  313. <form method="post" action="http://php.net/script.php">
  314. <input type="text" name="test1"></input>
  315. <input type="text" name="test2" />
  316. </form>
  317. <form method="post" action="https://php.net/script.php">
  318. <input type="text" name="test1"></input>
  319. <input type="text" name="test2" />
  320. </form>
  321. <form method="post" action="//php.net/script.php">
  322. <input type="text" name="test1"></input>
  323. <input type="text" name="test2" />
  324. </form>
  325. bool(true)
  326. *** Cleanup ***
  327. bool(true)
  328. string(6) "testid"
  329. bool(true)