Passing variables
The code below is supposed to log two people on using a text file placing the first "player" waiting for another, once a 2nd "player" is present loading a html screen.
Also i would like to then pass an array variable between them. Thanks for helping!
Dr Ben
<?php
session_start();
if (!isset($_POST['submit'])) {
echo "<form method='post'>";
echo " your name?<input type='text' name='uname'>";
echo " <input type='submit' name='submit'>";
echo "</form>";
} else {
$_SESSION['uname'] = $_POST['uname'];
echo "Welcome {$_SESSION['uname']}, your session id is ". session_id();
}
if (file_exists (waiting.txt))
fopen("battleships.html", "r+");
else
$file = fopen("waiting.txt", "w+");
$game = fread($file, filesize("waiting.txt"));
fclose($file);
$game = session_id();
$file = fopen("waiting.txt");
fputs($file, $game);
fclose($file);
?>
|