[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-18-2006, 04:52 AM   #1 (permalink)
NamePros Regular
 
Join Date: Aug 2005
Location: Leeds, UK
Posts: 260
70.00 NP$ (Donate)

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.
__________________
C905 - Sony Ericsson mobile phone with an 8 megapixel camera!
noswad is offline  
Old 05-18-2006, 05:03 AM   #2 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 07:06 AM   #3 (permalink)
NamePros Regular
 
Join Date: Aug 2005
Location: Leeds, UK
Posts: 260
70.00 NP$ (Donate)

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
__________________
C905 - Sony Ericsson mobile phone with an 8 megapixel camera!
noswad is offline  
Old 05-18-2006, 07:22 AM   #4 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 08:50 AM   #5 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 08:39 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85