What potential issue can arise when setting a cookie and redirecting to the same page in PHP?
The potential issue that can arise when setting a cookie and redirecting to the same page in PHP is that the cookie may not be immediately available on the page after the redirect due to the way cookies are processed by the browser. To solve this issue, you can set the cookie before sending any output to the browser, such as using the ob_start() function to buffer the output.
<?php
ob_start();
setcookie("example_cookie", "example_value", time() + 3600, "/");
ob_end_flush();
header("Location: ".$_SERVER['REQUEST_URI']);
exit;
?>