PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 27th, 2003, 04:14 PM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
PHP Custom Sessions Article Question??

Hi Ya Folks,

Just a quickie for all u PHP Pros...
I keep getting the following error every time the function expire() calls destroy, well i've renamed it to destroy_sess() but same difference...

Fatal error: Call to undefined function: destory_sess() in sess.php on line 149

I have included my sess.php file, but am really stuck on this one, i will be very grateful for any advice...

Also, the dev article I took the sess.php file from is:

http://www.devarticles.com/art/1/171/2

Cheers All,

Harvey

PHP Code:
<?php // sess.php - All the functions to administer sessions

include("common.php");
include(
"db.php");

dbConnect();

class 
session {

    var 
$key;
    var 
$timeout;

function 
start($timeout "") {

    
// create an array with all the letters of the alphabet
    
$letters range("a","z");
    
// declare the $key variable
    
$key "";

    
// generate our sessions key formatted such as #a#aa#
    
for($i 0$i 6$i++) {
        if((
$i == 0) || ($i == 2) || ($i == 5))
            
$key .= rand(0,9);
        if((
$i == 1) || ($i == 3) || ($i == 4))
            
$key .= $letters[rand(0,25)];
    }

    
// store the sessions key in a method of the class
    
$this->key $key;

    
// perform a conditional to test if the user defined the timeout and if not store the default value.
    
if($timeout == "")
        
$this->timeout 7200// five minutes
    
else
        
$this->timeout $timeout;

    return 
0;
}

// this function will kill the session
function destroy_sess($key="") {

    if (!isset(
$key))  {
      
$key="";
    }
    
// fetch the user key from cookie
    
$this->key $_COOKIE["sess_key"];

    
// delete session from database
    
$query mysql_query("DELETE FROM sessions WHERE sess_key = '" $this->key "'") or die("query failed - line 59");

    
// remove cookie from the user's computer
    
$delete setcookie("sess_key" $this->keytime()-3600);

    if (
$query && $delete) {
        
header("Location: <a href="http://www.dynamicwebprojects.co.uk/HTML/search.placement.php" target="_blank">[url]http://www.dynamicwebprojects.co.uk...h.placement.php[/url]</a>");
        
exit;
    }
    return 
0;

}

function 
checkAcc($uname,$pwd) {
    
$sql "SELECT * FROM smstaff WHERE staffuname='" $uname "' AND password='" md5($pwd) . "'";
    
$result mysql_query($sql);
    if (!
$result) {
      
error("login404","sess.php - Line 73");
    }
    if (
mysql_num_rows($result) == 0) {
      
error("login404","sess.php - Line 73");
      
destroy_sess();
      exit;
    }
}

// this function will register a value to session. (only one value, see replace() to update the value)
function register($val) {

    
// if key is not generated run start()
    
if($this->key == "")
        
$this->start();

    
$insert mysql_query("INSERT INTO sessions (sess_key, val, ip, sec_expire, stamp_expire, access) VALUES ('" $this->key"', '" addslashes($val) . "' , '" $_SERVER["REMOTE_ADDR"] . "' , " $this->timeout "," . (time() + $this->timeout) . "," time() .");");

    
// set the cookie that will store the session key
    
setcookie("sess_key",$this->key,time()+3600);

}

function 
read() {

    
// set $sess_val global - the variable of the session value.
    
global $sess_val;

    
// if the cookie doesn't exisit send them back to the login screen.
    
if(!$_COOKIE["sess_key"]) {
        
header("Location: stafflogin.php");
        echo 
"Cannot Find Cookie - line 104";
        exit;
    }

    
// fetch the session key from the cookie.
    
$this->key $_COOKIE["sess_key"];

    
// fetch the session value
    
$query mysql_query("SELECT val FROM sessions WHERE sess_key = '" $this->key "'") or die("query failed - line 97");

    if(
mysql_num_rows($query) == 0) {
        
header("Location: stafflogin.php");
        echo 
"0 Values in query - line 100";
        exit;
    }

    
$fetch mysql_fetch_array($query);

    
// store the session value to $sess_val
    
$sess_val stripslashes($fetch["val"]);

    
// test if session has reached the expiration point
    
$this->expire();

    
// this code will only run if expire() returned falsed - we update the last access point to now.
    
$update mysql_query("UPDATE sessions SET access = " time() . " WHERE sess_key = '" $this->key "'") or die("query failed - line 114");

}

// this function will test if the user has been inactive for the defined timeout
function expire() {

    
// fetch the last access and expirations from the database
    
$query mysql_query("SELECT access, sec_expire, stamp_expire FROM sessions WHERE sess_key = '" $this->key "'") or die("query failed - line 114");
    
$fetch mysql_fetch_array($query);

    
$access $fetch["access"];
    
$expire $fetch["sec_expire"];
    
$timeout $fetch["stamp_expire"];

    
// test if session is expired based on defined timeout
    
if (($timeout $access) <= ($expire $expire)) {
        
$this->destory_sess();
        
//die("Your session has expired.  Please re-login.");
    
}
}

// this function will update the session value
function replace($val) {

    
// fetch the user key from cookie
    
$this->key $_COOKIE["sess_key"];

    
// update the database with the new value
    
$query mysql_query("UPDATE sessions SET val = '" $val "' WHERE sess_key = '" $this->key) or die("query failed - line 77");
}
}
?>

Reply With Quote
  #2  
Old May 27th, 2003, 04:21 PM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Sorry everyone, but the following code in the sess.php file was typed incorrectly, and should be...

PHP Code:
if ($query && $delete) {
  
header("Location: [url]http://www.dynamicwebprojects.co.uk/HTML/search.placement.php[/url]");
  exit;



...cheers for all your help

Harvey

Reply With Quote
  #3  
Old May 29th, 2003, 10:38 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
Have you checked that you did not mistype the destroy_sess function when calling it?
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #4  
Old May 31st, 2003, 02:39 PM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
the destroy_sess() function is called destroy_sess(), but its still not finfing it...

...any other ideas??

Cheers,
Harvey

Reply With Quote
  #5  
Old June 1st, 2003, 07:22 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Change this line

PHP Code:
 $this->destory_sess(); 
to
PHP Code:
 destroy_sess(); 
does it still do the same thing?

Last edited by nicat23 : June 5th, 2003 at 12:28 PM.

Reply With Quote
  #6  
Old June 1st, 2003, 04:06 PM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
I've already tried that...

...No luck, same error. There must be an error in the code? Help!?

- Harvey

Reply With Quote
  #7  
Old June 1st, 2003, 05:03 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
Quote:
Originally posted by harvey_r01
I've already tried that...

...No luck, same error. There must be an error in the code? Help!?

- Harvey


Are you sure about that... take a look at your error line:

Fatal error: Call to undefined function: destory_sess() in sess.php on line 149


is it supposed to be destroy or destory?

Reply With Quote
  #8  
Old June 1st, 2003, 05:10 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 15
Where is the line with the error? Do you want us to count all your lines there until we find line 149?

If line 149 is inside the checkAcc operation, your problem is here:
PHP Code:
/*--------------------------------------------------
Problem
--------------------------------------------------*/
destroy_sess();
/*--------------------------------------------------
Problem Fix
--------------------------------------------------*/
$this->destroy_sess(); 

The $this-> is a reference pointer. When used inside a class definition, it means exactly what it says ( $this->function) - in short: USE THIS FUNCTION NAMED 'FUNCTION' INSIDE THIS CLASS DEFINITION. If you don't use that, it looks outside of the class. Since there is no function outside the class named that, you get undefined function error...
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #9  
Old June 1st, 2003, 05:25 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
There are two problems:

(1) - Line 71 : destroy_sess();


(2) - Line 140: $this->destory_sess();


Look at the spelling of this method call on line 140.
You really should spend more time double checking
your own code man.

Reply With Quote
  #10  
Old June 1st, 2003, 10:08 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 15
Quote:
Look at the spelling of this method call on line 140

Lol - I am glad you counted the lines. I refuse to count lines in a big birds nest of code - it is easy to do copying and pasting, but we should'nt have to do that. But good catch...

Reply With Quote
  #11  
Old June 2nd, 2003, 01:40 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
Jpenn,

yeah, you are so right... and believe me, I would have never done it had I not had the quick find feature of ultraedit.

Reply With Quote
  #12  
Old June 3rd, 2003, 03:36 AM
harvey_r01 harvey_r01 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Bournemouth
Posts: 37 harvey_r01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
LOL - What a FOOL!!!

Thanks everyone, I didn't realise I couldn't spell, I really should have double checked the error code!!

Sorry to waste your time guys...

Harvey

Reply With Quote
  #13  
Old February 25th, 2012, 01:40 AM
afrofeel afrofeel is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 1 afrofeel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 0
Lightbulb Developing-Custom-PHP-Sessions

Hallo fellow PHP programmers,

I'm building a site which uses sessions for identification and I came across the "Developing-Custom-PHP-Sessions" which I implemented for my site.
The result I am getting is not what I was expecting. Actually whether the user be active on not, the session destroys itself after the $timeout period.
I would like it to destroy only if the user is not active.

Has anyone used that script and help me out?

Thanks for your help

Reply With Quote
  #14  
Old May 28th, 2012, 04:18 AM
shivamagrawal shivamagrawal is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 1 shivamagrawal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 42 sec
Reputation Power: 0
I have setup a test file so i can try this out. I have tried to get it working but i am getting the following error.

Warning: file_get_contents(/public_html/#########.co.uk/Holiday Elite/storage/csv/form-results.csv) [function.file-get-contents]: failed to open stream: No such file or directory in /home/########/public_html/###########.co.uk/file.php on line 3

Fatal error: Call to undefined function mime_content_type() in /home/########/public_html/########.co.uk/file.php on line 16

Many thanks..

Reply With Quote
  #15  
Old May 28th, 2012, 08:12 PM
Linda269 Linda269 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 4 Linda269 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 42 sec
Reputation Power: 0
we want to the dll files and the jar filesURLURLURLURL

Reply With Quote
  #16  
Old January 1st, 2013, 01:09 AM
adamnelson adamnelson is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 adamnelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 9 sec
Reputation Power: 0
It would be nice if you share some more with us.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP Custom Sessions Article Question??


Developer Shed Advertisers and Affiliates


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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap