I am hosting web site using a inex.php file. I have setup a login for four different users which currently directs them to same index.php file.
I would like direct each individual to a specifice index.php file based on the user. I am very new to php and coding in general. Could anyone hlep me with this?
Thank you in advance
Here is my code for the index.php
<?php
//======================================================================
// Positions pic
//======================================================================
?>
<style type="text/css"> /*Initializing CSS code*/
img { float: right; }
</style>
<?php
//======================================================================
// Takes you to login
//======================================================================
?>
<?php include("/home/pi/html/password_protect.php"); ?>
<html>
<body>
<?php
//======================================================================
// creates logout
//======================================================================
?>
<a href="http://www.google.com/path/to/protected/page.php?logout=1">Logout</a>
<meta name="viewport" content="width=device-width, maximum-scale=1.0" />
<?php
//======================================================================
// Makes background color
//======================================================================
?>
<?php echo "<body style='background-color:purple'>"; ?>
<?php
//======================================================================
// Creates picture
//======================================================================
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title></title>
</head>
<body>
<?php
echo ("ENGR490");
?>
<div>
<img src="myPic.jpg" alt="myPic" />
</div>
</body>
</html>
<style>
input[type=radio] {
border: 1px;
width: 4em;
height: 4em;
}
input[type=submit] {
margin-left: 2em;
}
</style>
<?php
if (isset($_POST['Submit_one'])){
$on = "On";
$off = "Off";
$file = fopen("pump_one.txt","w+");
//read in user fields (text box or radio button
$radio_value_one = $_POST['on_off_one'];
//read in the radio buttons and write the status to file
if ($radio_value_one == $on){
fwrite($file, $on);
}
if ($radio_value_one == $off){
fwrite($file, $off);
}
//close
fclose($file);
}
$value_one = file_get_contents("pump_one.txt");
?>
<?php
$value_one = file_get_contents("pump_one.txt");
?>
<br>
<br>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method = "post">
<input type="radio" name ="on_off_one" <?php if ((isset($radio_value_one)) && ($radio_value_one==$on)) echo "checked";?> value = "On"> On
<input type="radio" name ="on_off_one" <?php if ((isset($radio_value_one)) && ($radio_value_one==$off)) echo "checked";?> value = "Off" > Off
<input type = "Submit" name ="Submit_one">
</form>
<h1>Tank one water request is...
<br>
<b><?php echo $value_one ?></b></h1>
<?php
if (isset($_POST['Submit_two'])){
$on = "On";
$off = "Off";
$file = fopen("pump_two.txt","w+");
//read in user fields (text box or radio button
$radio_value_two = $_POST['on_off_two'];
//read in the radio buttons and write the status to file
if ($radio_value_two == $on){
fwrite($file, $on);
}
if ($radio_value_two == $off){
fwrite($file, $off);
}
//close
fclose($file);
}
$value_two = file_get_contents("pump_two.txt");
?>
<?php
$value_two = file_get_contents("pump_two.txt");
?>
<br>
<br>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method = "post">
<input type="radio" name ="on_off_two" <?php if ((isset($radio_value_two)) && ($radio_value_two==$on)) echo "checked";?> value = "On"> On
<input type="radio" name ="on_off_two" <?php if ((isset($radio_value_two)) && ($radio_value_two==$off)) echo "checked";?> value = "Off" > Off
<input type = "Submit" name ="Submit_two">
</form>
<h1>Tank two water request is...
<br>
<b><?php echo $value_two ?></b></h1>
<?php
if (isset($_POST['Submit_three'])){
$on = "On";
$off = "Off";
$file = fopen("pump_three.txt","w+");
//read in user fields (text box or radio button
$radio_value_three = $_POST['on_off_three'];
//read in the radio buttons and write the status to file
if ($radio_value_three == $on){
fwrite($file, $on);
}
if ($radio_value_three == $off){
fwrite($file, $off);
}
//close
fclose($file);
}
$value_three = file_get_contents("pump_three.txt");
?>
<?php
$value_three = file_get_contents("pump_three.txt");
?>
<br>
<br>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method = "post">
<input type="radio" name ="on_off_three" <?php if ((isset($radio_value_three)) && ($radio_value_three==$on)) echo "checked";?> value = "On"> On
<input type="radio" name ="on_off_three" <?php if ((isset($radio_value_three)) && ($radio_value_three==$off)) echo "checked";?> value = "Off" > Off
<input type = "Submit" name ="Submit_three">
</form>
<h1>Tank three water request is...
<br>
<b><?php echo $value_three ?></b></h1>
<?php
if (isset($_POST['Submit_four'])){
$on = "On";
$off = "Off";
$file = fopen("pump_four.txt","w+");
//read in user fields (text box or radio button
$radio_value_four = $_POST['on_off_four'];
//read in the radio buttons and write the status to file
if ($radio_value_four == $on){
fwrite($file, $on);
}
if ($radio_value_four == $off){
fwrite($file, $off);
}
//close
fclose($file);
}
$value_four = file_get_contents("pump_four.txt");
?>
<?php
$value_four = file_get_contents("pump_four.txt");
?>
<br>
<br>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method = "post">
<input type="radio" name ="on_off_four" <?php if ((isset($radio_value_four)) && ($radio_value_four==$on)) echo "checked";?> value = "On"> On
<input type="radio" name ="on_off_four" <?php if ((isset($radio_value_four)) && ($radio_value_four==$off)) echo "checked";?> value = "Off" > Off
<input type = "Submit" name ="Submit_four">
</form>
<h1>Tank four water request is...
<br>
<b><?php echo $value_four ?></b></h1>
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "5";
header("Refresh: $sec; url=$page");
echo "Watch the page reload itself in 5 second!";
?>
</body>
</html>