NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help with sessions

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-18-2006, 05:52 AM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



Help with sessions


Hi it's me again

I have a page using sessions to obtain data from my database.

For example -

session_start();
echo("Premium Membership: $_SESSION[membership] ");

So if a user has a premium membership, it will display:

'Premium Membership: Yes'

If the databse field for membership is empty, is there a script to auto display:

'Premium Membership: No'

Thanks.
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
noswad is offline  
Old 05-18-2006, 06:03 AM   #2 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



It's probably best to just do a test at the start of your script and set it to 'no' if it's not found. That way, you won't have to continually test to see if it is set.

Do something like:
if (! isset( $_SESSION['membership'] ) ) {
$_SESSION['membership'] = 'no';
}

Hope that helps!
TwistMyArm is offline  
Old 05-18-2006, 08:06 AM THREAD STARTER               #3 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



Hi this works but there are a few problems...

For example:

When a user logs in, if the membership field is empty, the page displays:

'Premium Membership: '

Then when the page is refreshed it corrects itself to:

'Premium Membership: No'

However, when the user logs in and the membership field is 'Yes', the page displays:

'Premium Membership: Yes'

...but when the page is refreshed it changes to:

'Premium Membership: No'

lol

Thanks for trying though
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
noswad is offline  
Old 05-18-2006, 08:22 AM   #4 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



When exactly are you running that code that I put there?

It obviously needs to be between the two lines that you started with, but it almost looks as though it's been placed after the echo.

To test the problem of after refreshing reverting to 'no', for the time being you should use a different value for 'unset' session variables. That way you'll know pretty quickly on the refresh whether it's saying 'no' because it's been overwritten with 'no' or because it's just not remembering that it's set...
TwistMyArm is offline  
Old 05-18-2006, 09:50 AM   #5 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
the reason the problem happens on the first visit is because session data cannot beused in the script where it is set that is why it works on refresh as it was set on the previous initialisation of that page.

A way around this is after the session data has been set use a header redirect to the page you want them to see (making sure you attache the session id to the end of the address you send them as php does not automatically put attach this when you do a header redirect)
Peter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:31 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger