/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] read session in cakephp

Hi,

I am making a login script using cakephp.The check_login function from user model returns all data of the user if login succeed.

Inside the user controller if I just want to display

[code=php]echo $this -> Session -> read(“User.type”);[/code]

then nothing is displayed where as if I do

[code=php]$this->Session->write(‘type’, $user[‘User’][‘type’]);
echo $this->Session->read(“type”);[/code]

then it displays the data.

Code:

[code=php]if( ($user = $this->User->check_login($this->data)) )
{

$this->Session->write(‘type’, $user[‘User’][‘type’]);
echo $this->Session->read(“type”);

// save the user information to the session
$this->Session->write(‘User’, $user);
echo $this -> Session -> read(“User.type”); //display nothing
} [/code]

I have to know what I am doing wrong.

Please suggest..

Thanks,
Raj

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiAug 11.2009 — The user's data won't be automatically added to the session. You need to do that yourself as you found in your post.

However it would be easier to just use the built in AuthComponent to do this, then as well as super-simple user authentication, you can access the logged in user;s details at any point with AuthComponent::user().
Copy linkTweet thisAlerts:
@raj_2006authorAug 11.2009 — Thanks for your suggestion.

I am not familiar with AuthComponent but i can think that definately it will be easier.

I need to see how this AuthComponent works actually.

Thanks,

Raj
Copy linkTweet thisAlerts:
@raj_2006authorAug 11.2009 — Thats really great help...

Thanks mate..
Copy linkTweet thisAlerts:
@GreenMushroom16Aug 11.2009 — I found this 12 part tutorial when setting up the auth component:

http://www.jamesfairhurst.co.uk/

The authentication part is here:

http://www.jamesfairhurst.co.uk/posts/view/full_cakephp_application_part_6/

The author explains everything in details. Great for starters and mid-users.

Cheers
×

Success!

Help @raj_2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...