PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 8th, 2008, 07:15 PM
jakenoble's Avatar
jakenoble jakenoble is offline
System.out.println("eh?");
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2004
Location: Derbyshire
Posts: 817 jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 10 h 8 m 25 sec
Reputation Power: 25
Send a message via MSN to jakenoble
PHP5 - Broken Sessions

Hi All

I have been working on some OO code in PHP5 for a site. I have just broken sessions, and I have no idea how.

I only ever unset() them on a logout page, this is never viewed/accessedd in this case.

1) I POST to login, it validates, then writes the sessions
2) A META refresh then reloads the page with these valid sessions and takes me to my account
3) All is well
4) If I click refresh or go to another page, as soon as the new page loads (straight after I call session_start()) $_SESSION is completely empty, the PHPSESSID cookie remains, but the session data server side has gone.

Has anyone else had this happen unexpectedly to them also?
Is there anything in PHP that can unset or break sessions, even without calling unset()?

Thanks for any help, I am going out of my tree with this one

Reply With Quote
  #2  
Old May 10th, 2008, 06:50 PM
mr.mofo mr.mofo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 101 mr.mofo User rank is Lance Corporal (50 - 100 Reputation Level)mr.mofo User rank is Lance Corporal (50 - 100 Reputation Level)mr.mofo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 12 h 48 m 4 sec
Reputation Power: 3
Send a message via AIM to mr.mofo
Where is your session_start(); ?
It should be the very first line after <? php
__________________
We Live; We Love. We Hate; We Die.

Reply With Quote
  #3  
Old May 10th, 2008, 08:19 PM
GameYin GameYin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Whiteford, MD
Posts: 348 GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 11 h 54 m
Warnings Level: 5
Reputation Power: 60
Send a message via AIM to GameYin
MySpace
He said he did that. Post the code for the page that is "broken" and the page where session is set. The original one.
__________________
Adwords Professional
You can give me

Reply With Quote
  #4  
Old May 12th, 2008, 03:03 PM
jakenoble's Avatar
jakenoble jakenoble is offline
System.out.println("eh?");
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2004
Location: Derbyshire
Posts: 817 jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level)jakenoble User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 10 h 8 m 25 sec
Reputation Power: 25
Send a message via MSN to jakenoble
Quote:
Originally Posted by GameYin
He said he did that. Post the code for the page that is "broken" and the page where session is set. The original one.


Hi

Thanks for the input. I have included the code below, I do not know how much of a use it will be.

PHP Code:
Original - PHP Code
  1. function isCron()
  2. {
  3.     if(isset($_SERVER['SHELL']) &&  $_SERVER["SHELL"]== "/bin/sh")
  4.         return true;
  5. }
  6. if(!isCron())
  7. {
  8.     session_start();
  9.     date_default_timezone_set('Europe/London');
  10. }
  11.  
  12.  
  13.  
  14. date_default_timezone_set('Europe/London');
  15.  
  16.  
  17. define("SITE_GENERIC_ERROR_MESSAGE", WEBSITE." error - please go back and try again.");
  18.  
  19. ini_set('include_path', '.:'.PEAR_ROOT.':'.OBJECT_ROOT.':'.SCAFFOLD_ROOT.':'.UTIL_ROOT.':'.TYPES_ROOT.':'.SMARTY_ROOT.':'.IN  TERFACE_ROOT.'');
  20.  
  21. require_once ('ut_global_functions.inc');
  22. require_once ('interface_object.inc');
  23. require_once ('object.inc');
  24. require_once ('type.inc');
  25. require_once ('ut_page.inc');



This function ( login() ) is caled once POST data has been verified, this executes successfully and then calls onLogin.
PHP Code:
Original - PHP Code
  1.  
  2.     public function login()
  3.     {
  4.         if($this->load($this->login_admin_username,'username'))
  5.         {
  6.             if($this->get('lock_until') > time())
  7.                 return '<span class="error">You have failed to login in too many times, your account has been automatically locked for '.LOCKOUT_MINS.'</span>';
  8.  
  9.             else if(trim($this->login_admin_password) !=  $this->get('password'))
  10.             {
  11.                 $fails = $this->get("failed_logins");
  12.                 $fails++;
  13.                 $this->set("failed_logins", $fails);
  14.                 if($fails >= FAILED_LOGIN_LIMIT)
  15.                     $this->set("lock_until", time()+(60*LOCKOUT_MINS));
  16.                
  17.  
  18.                 $this->save();
  19.                
  20.                 return '<p class="error">The details you entered were incorrect.</p>';
  21.             }
  22.             else if(trim($this->login_admin_password) ==  $this->get('password'))
  23.                 if($this->onLogin())
  24.                     return '<span class="success">Your login was successful</span><meta  http-equiv="refresh" content="0;url='.LIVE_ADMIN_URL.'">';
  25.                 else
  26.                     return '<span class="error">An internal error occured while processing your login, please try again.</span>';
  27.             else
  28.                 return '<span class="error">An internal error occured while processing your login, please try again.</span>';
  29.         }
  30.         else
  31.             return '<span class="error">The details you entered were incorrect.</span>';
  32.     }


Line 23 above returns true and the page is redirected, once the page is redirected and I var_dump($_SESSION) everything is set. If I then refresh or go to another admin page the sessions have gone completely. onLogin function below is where the sessions are set.
PHP Code:
Original - PHP Code
  1.  
  2.     private function onLogin($isAuto = false)
  3.     {
  4.         $_SESSION['password'] = $this->login_admin_password;
  5.         $_SESSION['username'] = $this->login_admin_username;
  6.         $_SESSION['logged_in_at'] = time();
  7.  
  8.         $logins = $this->get('logins');
  9.         $logins++;
  10.        
  11.         if(!$isAuto)
  12.             $this->set("logins",$logins);
  13.            
  14.         $this->set("failed_logins",0);
  15.         $this->set("lock_until",0);
  16.         $this->save();
  17.  
  18.         return true;
  19.     }


Thanks for your time and efforts.

Jake

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Broken Sessions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway