Re: [PHP]Session redirection
SOmething like this. Session start must always be before you output any HTML or send any other headers or something.
If i'm right this should work (not sure, had to do it quickly)
Code:
<?php
session_start();
$_SESSION['username']=$username;
if(isset($_SESSION['username']
{
header('Location: home.php');
}
else
{ ?>
<html>
<title>~ Homepage ~</title>
<center>
<img src="images/jose.jpg"></img>
<h1>Welcome.</h1>
<h2>Please Login :)</h2>
<br /> <br /> <br />
<form action="login.php" method="POST">
Username: <input type='text' name='username'> <br /><br />
Password: <input type='password' name='password'> <br /><br />
<input type='submit' value='Login!'>
</form>
<br>
<a href="register.php">Don't Have an Account? Register now!</a>
</center>
</html>
<?php } ?>
Re: [PHP]Session redirection
Quote:
Originally Posted by
Guildjuhh
SOmething like this. Session start must always be before you output any HTML or send any other headers or something.
If i'm right this should work (not sure, had to do it quickly)
Code:
<?php
session_start();
$_SESSION['username']=$username;
if(isset($_SESSION['username']
{
header('Location: home.php');
}
else
{ ?>
<html>
<title>~ Homepage ~</title>
<center>
<img src="images/jose.jpg"></img>
<h1>Welcome.</h1>
<h2>Please Login :)</h2>
<br /> <br /> <br />
<form action="login.php" method="POST">
Username: <input type='text' name='username'> <br /><br />
Password: <input type='password' name='password'> <br /><br />
<input type='submit' value='Login!'>
</form>
<br>
<a href="register.php">Don't Have an Account? Register now!</a>
</center>
</html>
<?php } ?>
You only did the half thing..
PHP Code:
<?php
session_start();
$_SESSION['username'] = $username;
if(isset($_SESSION['username']))
{
header('Location: home.php');
}
else
{
?>
<html>
<title>~ Homepage ~</title>
<center>
<img src="images/jose.jpg"></img>
<h1>Welcome.</h1>
<h2>Please Login :)</h2>
<br /> <br /> <br />
<form action="login.php" method="POST">
Username: <input type='text' name='username'> <br /><br />
Password: <input type='password' name='password'> <br /><br />
<input type='submit' value='Login!'>
</form>
<br>
<a href="register.php">Don't Have an Account? Register now!</a>
</center>
</html>
<?php } ?>
Headers / Session_start must always become before ANY output.
Re: [PHP]Session redirection
Thanks alot Superfun!
You helped alot.
Now I can continue learning :D
lol.