Jump to content

[SOLVED] Sessions & client names


zang8027

Recommended Posts

Ok, i have a table that has the following columns:

 

User Name  |  User Password  | User Type (enum)

 

 

Now, i have a few pages on the site that are only available if you are signed in. These pages have the following php at the top:

 

<?php
//Refuse letting the user in unless logged in
include("security.php");
session_start();
?>

 

 

Here is security php

 

<?php
    session_start();
//if they bypassed login and are not logged in
if(!isset($_SESSION['priv'])){
//redirect
header("Location:login.php?error=bypass");
}

?>

 

Everything works fine there. The question that I have is that is there a way to show what user name is logged in? I want a to pull rows from another table where userID is equal to whoever is logged in.  IS there extra code that I need in my log in?

 

 

Here is the process login page that logs the user in.

 

 

<?php//Store variables the users choices from index page:
$namechoice=$_GET['userName'];
$passchoice=$_GET['userPass'];

//Make a connection to the server... connect("servername","username","password") (or die is optional to show error)
$link=mysql_connect("localhost","clikndin_tyler","$dbPass") or die("No server connection".mysql_error());
//connect to our database
$db=mysql_select_db("clikndin_clickndine") or die("No Database Connection ".mysql_error());
//construct a SQL query that selects users from DB
$query="SELECT * FROM clientTable WHERE userName='$namechoice' AND userPass='$passchoice'";

//run the query
$result=mysql_query($query);

//if there was a row returned....
if($row = mysql_fetch_array($result)) {


//begin a session, which lets us store sessions vars
session_start();

//store users infor a var to be used later on ($_SESSION[NEWNAME, ANYTHING]=$row['COLUMNNAME']
$_SESSION['priv']=$row['userType'];

//send user to main page:
header("Location:loginConfirm.php");
}
else {	
//close the connection
mysql_close($link);

//redirect the browser back to index with string that activates message
header("Location:login.php?error=nouser");


}


?>

Link to comment
https://forums.phpfreaks.com/topic/142696-solved-sessions-client-names/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.