PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a login form and when the user logs in successfully name and password match I send them to another page....
On this page it just says welcome back "user_name".....
I want to pass the user_name to the next page.
I have this code in the welcome.php page which is opened using the header function
<?php
//Variables used to access the database
$hostname = "localhost";
$database = "access_point_users";
$username = "**********";
$password = "**********";
//connection to the database
$ttt = mysql_connect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING']))
{
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "users"))
{
//Selects the user_name with the entered password
$sql = "SELECT Password FROM users WHERE User_Name = '$_POST[user_name]'";
mysql_select_db("access_point_users", $ttt) or die( "Unable to select the database");
$Result1 = mysql_query($sql) or die(mysql_error());
//Retrieves the password which matches the user_name
while ($row = mysql_fetch_array($Result1, MYSQL_BOTH))
{
//Compares the entered password with the retrieved user name
if($row[0]== $_POST["password"])
{
header("Location: ./welcome.php");
}
else
{
header("Location: ./error.php");
}
}
}
?>
<html>
<head>
<title>Access Point Login</title>
</head>
<body>
<h1>
<font color="red"><em><b>Login to use the Access Point</b></em></font>
</h1>
This access point is provided free of charge by UCC, all you need
is a wireless enabled device and off you go!
<br /><br />
<form name="users"method ="POST"action ="<?php echo $editFormAction;?>">
<address><label>User Name:</label></address>
<input type="text" name="user_name" value="" />
<br /><br />
<address><label>Password:</label></address>
<input type="password" name="password" value="" />
<br />
<br />
<input type="submit" name="submit" value="Login">
<br />
<br /><i>If you do not have an account please
<a href="/register.php"><span style="color:blue">Register.</span></a>
</i><hr /></i><hr /><input type="hidden" name="MM_insert" value="users"></form>
If you have any trouble with login/registration please contact the
<A HREF="mailto:cl8@student.cs.ucc.ie">Administrator</A> with the
exact title <i><b>Access Point login/registration. </b></i><br />
<font size="1">We can not be held responsible for any damaging programs/viruses etc
that you may download while using this access point. We recommend that
you have up-to-date anti-virus software running on your machine</font>
</body>
</html>
<html>
<head>
<title>Access Point Login Successful</title>
</head>
<body>
<h1>
<font color="red"><em><b>Welcome</b></em></font>
</h1>
Welcome back<?php echo $_POST["user_name"]; ?>.
<br /><br />
</i><hr /></i><hr />
If you have any trouble with login/registration please contact the
<A HREF="mailto:cl8@student.cs.ucc.ie">Administrator</A> with the
exact title <i><b>Access Point login/registration. </b></i><br />
<font size="1">We can not be held responsible for any damaging programs/viruses etc
that you may download while using this access point. We recommend that
you have up-to-date anti-virus software running on your machine</font>
</body>
</html>
session_start();
## validate your login here
$_SESSION['username'] = $_POST['username']
## now, wherever you want to call the username,
## just put echo $_SESSION['username'];
## validate your login
setcookie("username",$_POST['username'],time()+60*60*24*30);
## now you can call the username by using echo $_COOKIE['username'];
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Grim... wrote:
(I'm not sure it will make a difference, though. Did you try the print_r($_POST); thing? If so, what did it spit out?)
He's redirecting them to another page $_POST will no longer be set
I have a login form and when the user logs in successfully name and password match I send them to another page....
On this page it just says welcome back "user_name".....
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.