3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $formSubmitted = false; if( isset( $_SERVER["REQUEST_METHOD"] ) && "POST" == $_SERVER["REQUEST_METHOD"] ) { $postData = $_POST; $user = isset( $postData["user"] ) ? $postData["user"] : ""; $color = isset( $postData["color"] ) ? $postData["color"] : ""; if( !empty( $user ) && !empty( $color ) ) { setcookie( "cookie_name", $user, time() + 86400 ); setcookie( "cookie_color", $user, time() + 86400 ); $formSubmitted = true; } } ?> <html> <body> <form method='POST'> <h1>Cookie Monster Jar</h1> Please Enter Your First name: <input type="text" name="user"><br> <input type='radio' name='color' value='red'>red <input type='radio' name='color' value='green'>green <input type='radio' name='color' value='blue'>blue<br> <input type='submit' value='Submit'/> </form> <?php if( $formSubmitted ) : ?> <div> Your name is <?php echo $user; ?>,and your favorite color is <?php echo $color; ?>. Cookies has been saved. </div> <?php else : ?> <div> Cookies aren't saved yet. </div> <?php endif; ?> </body> </html>
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<html> <body> <form method='POST'> <h1>Cookie Monster Jar</h1> Please Enter Your First name: <input type="text" name="user"><br> <input type='radio' name='color' value='red'>red <input type='radio' name='color' value='green'>green <input type='radio' name='color' value='blue'>blue<br> <input type='submit' value='Submit'/> </form> <div> Cookies aren't saved yet. </div> </body> </html>