declaring session variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MattC
Forum Newbie
Posts: 1
Joined: Mon Aug 14, 2006 4:13 am

declaring session variables

Post by MattC »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


im new to php. I have this login script that works fine just trying ot add a session variable to get the data from the field usertype (this will be set as admin or user)

ive tried the code below (used in main cod shown below) but getting parser errors the parts i have added that are not functioning are

$usertype = $_POST['usertype'];

$_SESSION['valid_type'] = get($usertype, "admin");

Just want to know how to get this session to work correctly like the others do any help appreciated

main code below.

Code: Select all

<?
include "functions/include_fns.php";
if (isset($_POST['username']) && isset($_POST['password'])) {

$username = $_POST['username'];
$password = $_POST['password'];
$usertype = $_POST['usertype'];

if (login($username, $password, "admin")) {

$sql

$_SESSION['valid_user'] = $username;
$_SESSION['valid_name'] = getname($username, "admin");
$_SESSION['valid_type'] = get($usertype, "admin");

if (isset($_POST['url']) && !empty($_POST['url'])) {
$go_url = "".$url;
header("Location: $go_url");
} else {
header("Location: home.php");
}
exit;
} else {
//status = 0: Incorrect Username or password
//status = 1: Session has timed out or your are not logged in
header("Location: index.php?status=0");
exit;
}
} else {
header("Location: index.php?status=0");
exit;
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

you have $sql just floating in there. Start by taking that out. Might get rid of the parsing error.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

Post by PapiSolo »

Have you started a session? I din't see that in your code. It should be the first thing...
Post Reply