REGRESSION [ PHP ][ iOS ]: Two http/tests/cookies/same-site/set-first-party-* Tests...
[WebKit-https.git] / LayoutTests / http / tests / cookies / resources / cookie-utilities.php
1 <?php
2 function startsWith($string, $substring)
3 {
4     return substr($string, 0, strlen($substring)) === $substring;
5 }
6
7 function hostnameIsEqualToString($hostname)
8 {
9     return startsWith($_SERVER["HTTP_HOST"], $hostname);
10 }
11
12 function resetCookies()
13 {
14     if (hostnameIsEqualToString("127.0.0.1")) {
15         resetCookiesForCurrentOrigin();
16         header("Location: http://localhost:8000" . $_SERVER["PHP_SELF"]);
17     } elseif (hostnameIsEqualToString("localhost")) {
18         resetCookiesForCurrentOrigin();
19         header("Location: http://127.0.0.1:8000" . $_SERVER["PHP_SELF"] . "?runTest");
20     }
21 }
22
23 function shouldResetCookies()
24 {
25     return empty($_SERVER["QUERY_STRING"]);
26 }
27
28 function wkSetCookie($name, $value, $additionalProperties)
29 {
30     $cookieValue = $name . "=" . $value;
31     foreach ($additionalProperties as $name => $value) {
32         $cookieValue .= "; " . $name;
33         if (isset($value))
34             $cookieValue .= "=" . $value;
35     }
36     header("Set-Cookie: " . $cookieValue, FALSE /* replace */);
37 }
38
39 function deleteCookie($name)
40 {
41     setcookie($name, "deleted", time() - 86400, "/");
42 }
43
44 function _deleteCookieCallback($value, $name)
45 {
46     deleteCookie($name);
47 }
48
49 function resetCookiesForCurrentOrigin()
50 {
51     array_walk($_COOKIE, '_deleteCookieCallback');
52 }
53 ?>