Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

some session variable?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

some session variable?

Postby arobert74 » Sun Apr 27, 2014 3:24 pm

Hi
Let me try and explain what I am looking for, hope I can.
I have this website I created which is like craigslist, closet I can describe that everyone should know of.
I have similar functionality where user would select the region (city) from the home page which then search and post would be specific to that region. I think there is a way to add a "variable" in PHP that would enable the session know which region user selected. Something similar to the functions that would only be available once the user is logged in. Like creating a post requires user to be logged in.
So looking for any pointers how to add those "variables" to my site, what are they exactly.

Thanks for any pointers.

Robert
arobert74
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Apr 27, 2014 3:17 pm

Re: some session variable?

Postby seandisanti » Sun Apr 27, 2014 7:11 pm

You could definitely use a session variable to persist their selection, but you should also save it in their user record in the database. That way when they log in, their user object is populated into session and persists with them across pages
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: some session variable?

Postby arobert74 » Mon Apr 28, 2014 6:29 am

Hi

Thank you for the reply and link in other post.
Do you have any extra information to share on saving session record in database then able to check versus that value in later pages / certain fields?

Thanks
arobert74
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Apr 27, 2014 3:17 pm

Re: some session variable?

Postby seandisanti » Mon Apr 28, 2014 8:21 am

When dealing with logins etc, I've found that object oriented is the best way to go. I typically have a user object that is created at login, and instantiating it grabs a lot of values from the database and stores them into the user object that is then saved in the session. That way I know I have everything I need on any page. I've posted a few user classes on the forum in response to questions about password recovery, remembering login etc, searching the forum for the precise functionality you're looking for should yield some helpful results.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.