-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsession.phpmeow.class.php
More file actions
71 lines (60 loc) · 1.4 KB
/
session.phpmeow.class.php
File metadata and controls
71 lines (60 loc) · 1.4 KB
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
<?php
/*
* phpMeow - A Cute and Fuzzy Alternative to CAPTCHA
* Created by Kris Craig. April - July, 2011.
*
* phpMeow is the first fully-functional, secure
* implementation of KittenAuth in PHP.
*
* This software is open-source and you're free to
* use and/or distribute it as you see fit. See
* LICENSE file for more information.
*
* Get the latest version at: http://www.github.com/sirkris/phpmeow
*/
class phpmeow_session
{
/* Avoids that pesky notice error if the session was already started previously in the stack. --Kris */
function start()
{
if ( !isset( $_SESSION ) )
{
session_start();
}
}
/* Generates a random string for use as a new sessionid or any other purpose. --Kris */
function generate_sid( $chars = 100, $alpha = TRUE, $numeric = TRUE, $symbols = TRUE, $timestamp = TRUE )
{
if ( $chars <= 0 || !is_numeric( $chars ) )
{
return FALSE;
}
$salt = NULL;
if ( $alpha == TRUE )
{
$salt .= "abcdefghijklmnopqrstuvwxyz";
}
if ( $numeric == TRUE )
{
$salt .= "1234567890";
}
if ( $symbols == TRUE )
{
$salt .= "-_";
}
$sid = NULL;
for ( $c = 1; $c <= $chars; $c++ )
{
$sid .= $salt{mt_rand( 0, strlen( $salt ) - 1 )};
if ( mt_rand( 0, 1 ) == 1 )
{
$sid{strlen( $sid ) - 1} = strtoupper( $sid{strlen( $sid ) - 1} );
}
}
if ( $timestamp == TRUE )
{
$sid .= time();
}
return $sid;
}
}