Hello. Pretty new to php, and was wondering if someone point me in the right direction? I am assuming this is pretty easy for more experiences php’ers
Basically I just need a box on my homepage where users can type in their username, and hit ‘login’… from there it will take them to that directory on the website.
ie:say my site is www.angorashop.com , they enter a user name of testuser into the box, hit login, and it simply redirects them to www.angorashop.com/testuser
Thanks ahead of time!
jemz
July 18, 2013, 8:54pm
2
Hi,maybe i can help, Lets assume that you already click the link log-in.
this is your form login.php
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
$ok = loginUser($username,$password);
if($ok == "success"){
header('location:www.angorashop.com/testuser');
}
else
echo "Invalid username and password";
}
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label>your username</label>
<input type="text" name="username">
<label>your password</label>
<input type="text name="password">
<input type="submit" name="login">
</form>
jemz:
Hi,maybe i can help, Lets assume that you already click the link log-in.
this is your form login.php
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
$ok = loginUser($username,$password);
if($ok == "success"){
header('location:www.angorashop.com/testuser');
}
else
echo "Invalid username and password";
}
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label>your username</label>
<input type="text" name="username">
<label>your password</label>
<input type="text name="password">
<input type="submit" name="login">
</form>
Hmm… perhaps I didn’t do a good job at explaining
There will be no password involved on the first screen. This will simply be used to collect their username, and pass it through to the URL.
ie: Enter username: (lets say they enter jemz)… They click ‘proceed’ … and it takes them to http://angorashop.com/jemz
Make sense?
force
July 18, 2013, 10:37pm
4
Any input fields from an HTML form with either end up in the $_GET or $_POST reserved variables (depending on the form’s method attribute).
To redirect users to another page using PHP, you can use this:
header("Location: http://example.org");