Web Design Forum: PHP Sessions Code Stopping Sessions - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP Sessions Code Stopping Sessions Rate Topic: -----

#1 User is offline   lee sands 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 134
  • Joined: 14-August 10
  • Reputation: 0
  • Gender:Male
  • Location:Gosport, Hampshire, UK
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 23 January 2012 - 04:11 PM

Hi All I Have A File Called session.php
<?php
       
	function _open() {
		
		global $_sess_db;
 
		$_sess_db = mysql_connect(CUR_HOST, SYS_USER , SYS_PASS);
		
		mysql_select_db(CUR_DB, $_sess_db);
	
	}
 
	function _close() {
		
		global $_sess_db;
 
		return mysql_close($_sess_db);
	
	}
	
	function _read($id) {
		
		global $_sess_db;
 		
		if ($db_result= mysql_query("SELECT data FROM cms_sessions WHERE id = '$id'",$_sess_db)) {
			
			if (mysql_num_rows($db_result)) {
				
				$record = mysql_fetch_assoc($db_result);
 
				return $record['data'];
			}

		}
 
		return '';
	}
	
	function _write($id, $data) {
		
		global $_sess_db;
 		
		global $id;
		
		global $data;
		
		$access = time();
 
		$sql = "REPLACE INTO cms_sessions VALUES ('$id', '$access', '$data')";
 
		return mysql_query($sql, $_sess_db);
	
	}
	
	function _destroy($id) {
		
		global $_sess_db;
 
		$sql = "DELETE FROM cms_sessions WHERE id = '$id'";
 
		return mysql_query($sql, $_sess_db);
	
	}
	
	function _clean($max) {
		
		global $_sess_db;
 
		$old = time() - $max;
		
		$old = mysql_real_escape_string($old);
 
		$sql = "DELETE FROM cms_sessions WHERE access < '$old'";
 
		return mysql_query($sql, $_sess_db);

	}
	
	session_set_save_handler('_open','_close','_read','_write','_destroy','_clean');
	
	session_start();
 	
	?>


but when i use my site none of the
$_SESSION['value']
it dont work it just shows error messages like

Quote

Notice: Undefined variable: _SESSION in C:\xampp\htdocs\cms\library\login.class.php on line 49

any ideas to get it working
0

#2 User is offline   websiteprodigy 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-January 12
  • Reputation: 1
  • Gender:Male
  • Location:Nottingham
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 23 January 2012 - 05:17 PM

You need to make sure that session_start is the first line in a script that uses session vars, try putting it before your functions.
0

#3 User is offline   lee sands 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 134
  • Joined: 14-August 10
  • Reputation: 0
  • Gender:Male
  • Location:Gosport, Hampshire, UK
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 23 January 2012 - 05:32 PM

i have it is at the bottom of that file
0

#4 User is offline   websiteprodigy 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-January 12
  • Reputation: 1
  • Gender:Male
  • Location:Nottingham
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 23 January 2012 - 05:43 PM

View Postlee sands, on 23 January 2012 - 05:32 PM, said:

i have it is at the bottom of that file


You are calling a function session_set_save_handler() before the session_start() which may well be needing the session_start() to be been called first.

session_start needs to be the first line of code in any script that uses it.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users