Solved

How to check if custom Wordpress session is set

Posted on 2016-09-08
7
36 Views
Last Modified: 2016-09-08
I'm trying to figure out how to check if a custom Wordpress session is set.

I set it like this:
$session->set_userdata( 'loggedIn', $loginGood );

Open in new window


Then when looking it up on other pages I use this:
$session->userdata('loggedIn')

Open in new window


I tried checking to see if set like:
if(isset($session->userdata('loggedIn')))

Open in new window


But the above is incorrect syntax.
0
Comment
Question by:N R
  • 4
  • 3
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41789674
Are you using this?
https://wordpress.org/plugins/wp-session-manager/

The syntax looks correct (except for missing semi-colons at the end).  What's the issue?  Can you assign the value of $session->userdata() to a variable?
0
 
LVL 11

Author Comment

by:N R
ID: 41789681
Yes so assigning the session is working.  

But when trying to see if the session is set like this I get a syntax error in my editor and the page is just a white page and does not load.

if(isset($session->userdata('loggedIn'))){
	echo 'working';
}else{
	echo 'not working';
}

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41789699
OK, I think this may be because isset() is looking for a variable, not a function call.  Maybe try it like this:
$x = $session->userdata('loggedIn');

if(!empty($x)){
    echo 'working';
}else{
    echo 'not working';
}

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Author Comment

by:N R
ID: 41789713
Then I get the problem where the variable isn't set.
Fatal error: Call to a member function userdata() on a non-object

Open in new window

0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41789736
You may need to use global $session in this context.
0
 
LVL 11

Author Comment

by:N R
ID: 41789776
All for that then as well, anything special with those ans WP?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41790071
Yeah, I don't know why WP does not just use the PHP session - so much easier!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now