- session_start: documentation ( source)
<?php
session_start();
if ((!isset($_SESSION["username"]) && !isset($_SESSION["s1"]) && !isset($_SESSION["s2"]))) {
$_SESSION["firstrun"] = "true";
$_POST = array();
}
?>
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="jquery-1.11.0.js"></script>
</head>
<script>
$(function() {
$('#enter').click(function() {
console.log("clicky"); //Debug
//Get value from the inputs
var user_input = $("#username").val();
var s1_input = $("#s1").val();
var s2_input = $("#s2").val();
//Make a jquery post to the session.php with the users data and then redirect to the next page
jQuery.post("session.php", {username:user_input, s1:s1_input, s2:s2_input}, function(data){
if (data == "true") {
window.location.replace("strings.php"); // Javascript redirect
}
});
});
});
</script>
<body>
Enter a username:
<input type="text" name="username" id="username" value=""/>
<br/> <br/>
Pick a string:
<input type="text" name="s1" id="s1" value=""/>
<br/> <br/>
Pick another string:
<input type="text" name="s2" id="s2" value=""/>
<br/> <br/>
<input type="button" name="enter" id="enter" value="Go play with strings!"/>
<br/> <br/>
</body>
</html>