garrensilverwing
New Member
- Messages
- 148
- Reaction score
- 0
- Points
- 0
Now that I got my login system working (thanks a lot garrettroyce) I want people to be able to log in on every page of my website, I went through and added all the code to every page (very tedious) but it only works on the home page. When I try logging into any other page it just refreshes the page and doesnt create a session (there are no errors to speak of). However, If i log into the homepage it recognizes I am logged in on every other page and I can subsequently log out. here are the codes the first is the homepage's (brianwallchess.x10hosting.com) code and the second is for brianwallchess.x10hosting.com/news any help would be appreciated.
homepage:
News homepage:
homepage:
Code:
<?php
if(isset($_SESSION['id']))
{$user = $_SESSION['user'];
echo "<span class=\"date\">You are currently logged in as $user! <a href=\"logout.php\">Click here to log out.</a></span>";}
else{
if(!$_POST['submit'])
{
?><form method="post" action="http://www.brianwallchess.x10hosting.com" class="form">
<span class="date">
Username
<input type="text" name="username" maxlength="16" style="height: 19px; width: 90px" />
Password
<input type="password" name="password" maxlength="16" style="height: 18px; width: 90px" />
<input type="submit" name="submit" value="Login" style="height: 20px" class="date" />
</span>
</form>
<a href="register">Register Here</a>
<?php }
else {
$user = protect($_POST['username']);
$pass = protect($_POST['password']);
if($user && $pass)
{
$pass = md5($pass);
$sql="SELECT id,username,first FROM `members` WHERE `username`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
$_SESSION['id'] = $row['id'];
$_SESSION['user'] = $row['username'];
$_SESSION['first'] = $row['first'];
$first = $_SESSION['first'];
echo "<span class=\"date\">$first, you are now logged in!</span>";
}
else {
echo "<span class=\"date\">The username and/or password you entered is invalid. ";
echo "<a href=\"javascript:history.go(-1)\">Try again</a> ";
echo "or <a href=\"register\">register</a></span>";
}
}
}
}
?>
Code:
<?php
if(isset($_SESSION['id']))
{$user = $_SESSION['user'];
echo "<span class=\"date\">You are currently logged in as $user! <a href=\"../logout.php\">Click here to log out.</a></span>";}
else{
if(!$_POST['submit'])
{
?><form method="post" action="http://www.brianwallchess.x10hosting.com/news" class="form">
<span class="date">
Username
<input type="text" name="username" maxlength="16" style="height: 19px; width: 90px" />
Password
<input type="password" name="password" maxlength="16" style="height: 18px; width: 90px" />
<input type="submit" name="submit" value="Login" style="height: 20px" class="date" />
</span>
</form>
<a href="../register">Register Here</a>
<?php }
else {
$user = protect($_POST['username']);
$pass = protect($_POST['password']);
if($user && $pass)
{
$pass = md5($pass);
$sql="SELECT id,username,first FROM `members` WHERE `username`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
$_SESSION['id'] = $row['id'];
$_SESSION['user'] = $row['username'];
$_SESSION['first'] = $row['first'];
$first = $_SESSION['first'];
echo "<span class=\"date\">$first, you are now logged in!</span>";
}
else {
echo "<span class=\"date\">The username and/or password you entered is invalid. ";
echo "<a href=\"javascript:history.go(-1)\">Try again</a> ";
echo "or <a href=\"../register\">register</a></span>";
}
}
}
}
?>