Jump to content

Recommended Posts

I am trying to allow my users to login to the site 1 time and then not have to login again until they have closed the window. I am using the following script wich I found on this site as a tutorial and have modified to authenticate my users:

login.php

[code]<?php
session_start();

header("Cache-control: private");

$user = $_POST['username'];
$pass = $_POST['password'];

include("db.php");

// Check to see if the user exists.

$sql_user_check = "SELECT username FROM users WHERE username='$user'";
$result_name_check = mysql_query($sql_user_check) or die(mysql_error());
$usersfound = mysql_num_rows($result_name_check) or die(mysql_error());

// If the user is not found note that and end.
if($usersfound < 1){
$error = "User ".$user." was not found in the database.";

$user = $_POST['username'];
$pass = md5($_POST['password']);
$sql = "select * from users where `username` = '$user'";
$result = mysql_query($sql);
while ($text = mysql_fetch_array($result)) {
$id = $text['id'];
$password = $text['encrytpass'];
$access = $text['access'];
}
if ($pass == $password) {
$error = "Wrong Username / Password <a href=\"?act=login\">Back</a>";

// If the passwords do match, let in and go to the session variables.
}else{
$_SESSION['userid'] = $text['userid'];
$_SESSION['first_name'] = $text['first_name'];
$_SESSION['last_name'] = $text['last_name'];
$_SESSION['username'] = $text['username'];
$_SESSION['password'] = $text['password'];
$_SESSION['encryptpass'] = $text['encryptpass'];
$_SESSION['email'] = $text['email'];
$_SESSION['location'] = $text['location'];
$_SESSION['steamid'] = $text['steamid'];
$_SESSION['handle'] = $text['handle'];
$_SESSION['bio'] = $text['bio'];
$_SESSION['photo'] = $text['photo'];
$_SESSION['team_name'] = $text['team_name'];
$_SESSION['team_tag'] = $text['team_tag'];
$_SESSION['access'] = $text['access'];
$_SESSION['webs'] = $text['webs'];
$_SESSION['priv_message'] = $text['priv_message'];
}
}

if(!$_SESSION['username']){
if($error){
echo $error;
include("index.php");
}else{
header("Location: index2.php");
  }
    }else{
echo "<html><head><title>Welcome Back</title></head>Welcome back ". $_SESSION['username'] .".<a href=index2.php>Click here</a> to proceed.";
}
?>[/code]

here is the code I am using on index2.php to display information if the user is logged in:

[code]<?php session_start();
if(!$_SESSION['username']){
echo "You are logged in as:". $_SESSION['username'] ."<br/><br/>";
}else{
echo "<font id=UserPanelText />You are not logged in.<br/><br/>";
}
$newpms = $_SESSION['priv_messages'];
if($newpms > "0"){
echo "<a href=?page=newpmessage=$id>Unread Messages</a> (". $newpms .")<br/>";
}else{
echo "<font id=UserPanelText /><a href=?page=pmessages=$id>Mailbox</a><br/><font id=UserPanelText /><a href=?page=user_panel>User Panel</a><br/>";
}
?>
</div>
<div style="position: absolute; top: 225; left: 780;">
<?php
include("db.php");
$sql = "SELECT * FROM `matches` order by `id` DESC LIMIT 0,3";
  $result    = mysql_query($sql) or die(mysql_error());
  $num    = mysql_num_rows($result);
  while ($text = mysql_Fetch_array($result)) {
$id = $row['id'];
$team1 = $row['home_team'];
$team2 = $row['away_team'];
$score1 = $row['score_one'];
$score2 = $row['score_two'];

$sql2 = "SELECT $id FROM `matches` WHERE `id`='$id'order by `id` DESC LIMIT 0,3";
$result2    = mysql_query($sql2) or die(mysql_error());
$num2    = mysql_num_rows($result2);
echo '
<tr><td> $id </td><td height="18" width=35 valign="bottom" align="left"><font id=ctext />n2p <font id=dash />vs<font id=ttext /> $team2 </td><td width="34" height=18 align="right" valign="bottom"><font id=ctext /> $score1 <font id=dash />-<font id=ttext /> $score2 </td></tr>';
}
?>[/code]

I am getting the not logged in message even though I beleive I have set the users sessions correctly. I have tried everything I can in my limited knowledge of php and also have searched google with no results.

here is an example of what is happening.
[url=http://n2p.ventgaming.com]http://n2p.ventgaming.com[/url]
user: test
pass: test
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.