| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | Sessions (2 Problems) I cant seem to get the data to display from the session, the code im using is below. The header file contains the session_start(); and db information. Heres my full login.php: PHP Code: PHP Code: My next problem is that the session_destroy() isnt working... heres the code PHP Code: |
| |
| | #2 (permalink) |
| Senior Member | In login.php you have a while loop. You do not need this loop as you are retrieving 1 row and I believe this is causing your problem (the session is not being populated) Regarding the session destroy. In which way is it not working? Just a note depending on what is in header (ie how it decides on whether to create a session) your else statement in the last piece of code will never be invoked as session_id() will always contain a session id. I tend to set a constant that declares whether someone is signed in or not. When it comes to the sign out script I check whether that constant is true or false. Although not related to your problem, you are using short tags I highly advise that you stop using them and use the full tags. Some servers have short tags disabled. Standard PHP tags are the only ones guaranteed to work on any server running PHP.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #3 (permalink) | ||
| Senior Member | Quote:
its doing this code PHP Code: My header just contains: PHP Code: What do you mean by short tags? I used the code a tutorial had, because Ive never done sessions before... :/ I cant test what you said for the login, because i dont know how to logout :P Quote:
PHP Code: PHP Code: PHP Code: Last edited by killaklown; 11-09-2007 at 04:07 PM. | ||
| |
| | #4 (permalink) |
| Senior Member | short tags are <? ideally you should always use <?PHP A problem you have in your pages is that if(session_id()!='') is never going to be met as at the start of every page load you call session_start() so a session id will always be present.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #5 (permalink) | ||
| Senior Member | Quote:
Oh, i guess thats just a habit now... Quote:
| ||
| |
| | #6 (permalink) | |
| Senior Member | Quote:
PHP Code: if($_SESSION['login']) to logout you would still simply do session_destroy
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | |
| |
| | #7 (permalink) |
| Senior Member | Thanks, +rep Gonna try that way, and see what happens. Yep, that fixed the data showing problem, and the logout problem. (getting rid of the 'while' part gave me a white page, so i put it back in, and it worked) Thanks again! (i think i was going to pull some hair out if i couldnt get it fixed today )I just have one question, would doing "$_SESSION['login'] = true;" limit the number of people who can be online at a time? Would it better to use "define('LOGGED_IN',true);" instead? Last edited by killaklown; 11-09-2007 at 04:47 PM. |
| |
| | #9 (permalink) |
| Senior Member | pm'd you
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |