Hi
I don't know what this script is part of, but I get the sense that your service contains multi pages, so I think some logic needs to be adjusted!
One of the most important things you should always do, is to make your code easy to modify or update without the need to update every script in the service!
Session control is the heart of any protected service, by centralizing your sessions control you will make your total script better, because keeping each major control separate will help keep your code truly organized!
Lets look at your script!
Start with this line...
PHP Code:
session_start();
This should be replaced and placed in a include file! Where your session control will be maintained!
session control should contain the following....
1. is there already a active session?
2. if there is should they redirected to a service page?
3. is the session cookie based or is it passed via a URL query!
4. if it's URL based, you must define the session strings that will need to be added to all URL strings to maintain the session!
5. if there is no session create a new one
6. then begin the session!
By doing this you will cover all the logic that your service needs and also allow for updates, like changing over to database controlled sessions!
Now lets look at other things in your script!
PHP Code:
$action = addslashes($_GET['action']);
if($action == 'logout') {
session_destroy();
}
assigning a $var to a already declared $var is wasteful and not needed! Also always assign the session to an empty array() before destroying it!
PHP Code:
if ( isset ( $_GET['action'] ) && $_GET['action'] == 'logout' )
{
$_SESSION = array ();
session_destroy ();
}
Again, assigning a $var to a already declared $var is wasteful and not needed!
every time you do this, you are using another memory address
PHP Code:
$signin = $_POST['signin'];
Try to use Perl type regex(s), they are more system friendly
PHP Code:
if(eregi('[~`!@#$%^&*()-+=|\'";:.,?/\\]', $_POST['login'])) {
$invalid = '<font color="#FF000"><b>Invalid characters.</b></font>';
}
also you did not define 'invalid', which allows for anyone to pass it a value to your script! Which also would allow anyone to by-pass part of your script!
PHP Code:
$invalid = '';
if ( !preg_match ( "/^[a-z0-9_]+$/is", $_POST['login'] ) )
{
$invalid = '<font color="#FF000"><b>Invalid characters.</b></font>';
}
This next if() could be by-passed because 'invalid' was not defined!
PHP Code:
if(!$invalid) {
There are other problems, including your database query, and more un-needed assign of var(s)!
J!
Bookmarks