Is there anyway to include certain variables from one php file and receive them in another file? I know you can include a whole file but in my case the program would not work because the program would try to redirect to user_details.php inside that file. So instead I tried to do include 'process.php.$username';
in user_details.php but that doesn't work.
Any help would be appreciated thanks.
Here is my code:
process.php
$username = $_POST["user"];
$password = $_POST["pass"];
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
mysql_connect("localhost", "root", "");
mysql_select_db("message_board");
$result = mysql_query("select * from users where username = '$username' and password = '$password'") or die("Failed to query database ".mysql_error());
$row = mysql_fetch_array($result);
if ($row["username"] == $username and $row["password"] == $password) {
echo "Login success! Welcome ".$row["username"], " and ".$row["user_permissions"];
header('location: user_details.php');
} else {
echo "Failed to login! \n";
echo '<a href="login.php">Back to Login</a>';
}
user_details.php
<html>
<head>
<title>user_details</title>
</head>
<body>
<div id="main">
<?php
include 'process.php.$username';
include 'process.php.$password';
mysql_connect("localhost", "root", "");
mysql_select_db("message_board");
$result = mysql_query("select * from users where username = '$username' and password = '$password'") or die("Failed to query database ".mysql_error());
$row = mysql_fetch_array($result);
echo "user permissions: ".$row["username"].$row["user_permissions"];
?>
</div>
</body>
</html>