Solved

How to check if custom Wordpress session is set

Posted on 2016-09-08
7
120 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:Nathan Riley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 110

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 12

Author Comment

by:Nathan Riley
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 110

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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 12

Author Comment

by:Nathan Riley
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 110

Accepted Solution

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

Author Comment

by:Nathan Riley
ID: 41789776
All for that then as well, anything special with those ans WP?
0
 
LVL 110

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

635 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