undefined index: user

images php coding issues or problems here.

Moderators: macek, egami, gesf

joeymanzano
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Oct 10, 2012 10:20 pm

undefined index: user

Postby joeymanzano » Wed Oct 10, 2012 10:33 pm

new member here, ...when im trying to try a simple code then i have encountered a undefined index: error ... i would like to know on how to fix this error.. thanks in advance.

with this code auth.php

<?php
$users = array(
"admin" => "adminpass",
"member1" => "member1pass"

);
//Returns true if $username and $password are valid
function credentials_valid($username, $password){

global $users;
return isset($users[$username]) &&
$users[$username] == $password;

}

//Logs into the user $user
function log_in($user){

$_SESSION['user'] = $user;
}

//Returns the currently logged in user (if any)
function current_user(){
return $_SESSION['user'];
}

?>
Attachments
undefined index.jpg
and this is the error...
undefined index.jpg (25.13 KiB) Viewed 1099 times

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: undefined index: user

Postby seandisanti » Thu Oct 11, 2012 8:09 am

in order to work with session variables you need to have a session_start()

joeymanzano
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Oct 10, 2012 10:20 pm

Re: undefined index: user

Postby joeymanzano » Thu Oct 11, 2012 8:00 pm

thanks for the reply sir, mmmm, yes already have a session_start() @ this attachment
Attachments
header.jpg
header.jpg (62.11 KiB) Viewed 1082 times

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: undefined index: user

Postby egami » Fri Oct 12, 2012 6:58 am

You need to make sure that session_start() is started every time a page is called.


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest