admin mode > security
hi! I have this script. do you see any security flaw? is it safe enough?
auth.php
PHP Code:
<?
$id = "user" ;
$pw = "password" ;
function auth (){
header ( "WWW-authenticate:basic realm=\"Admin Mode\"" );
header ( "HTTP/1.0 401 unauthorized" );
echo "
<script>
alert('Just the Admin can access, sorry.');
history.back(1);
</script>
" ;
exit;
}
if(! $PHP_AUTH_USER or ! $PHP_AUTH_PW ){
auth ();
}else{
if( $id != $PHP_AUTH_USER or $pw != $PHP_AUTH_PW ) auth ();
}
?>
and here's the file
PHP Code:
<?
include "auth.php" ;
< form action = "" method = "post" >
< input blah >
< input blah >
</ form >
?>
Last edited by Michaelttkk; 01-25-2007 at 07:33 PM .
Learning never ends!
Why the javascript?
PHP Code:
<?php
$id = "user" ;
$pw = "password" ;
if ( !isset( $_SERVER [ 'PHP_AUTH_USER' ] OR !isset( $_SERVER [ '$PHP_AUTH_PW' ]
OR $id <> $_SERVER [ 'PHP_AUTH_USER' ] OR $pw <> $PHP_AUTH_PW ) {
header ( 'WWW-Authenticate: basic realm="Admin Mode"' );
header ( 'HTTP/1.0 401 unauthorized' );
echo 'Just the Admin can access, sorry.<br>' ;
echo '<a href="' . $_SERVER [ 'HTTP_REFERER' ] . '">Back</a>' ;
exit;
}
?>
I tried the code, I included it in another page but the page goes blank
Learning never ends!
Sorry, missing a ( .
PHP Code:
<?php
$id = "user" ;
$pw = "password" ;
if ( !isset( $_SERVER [ 'PHP_AUTH_USER' ]) OR !isset( $_SERVER [ '$PHP_AUTH_PW' ])
OR $id <> $_SERVER [ 'PHP_AUTH_USER' ] OR $pw <> $PHP_AUTH_PW ) {
header ( 'WWW-Authenticate: basic realm="Admin Mode"' );
header ( 'HTTP/1.0 401 unauthorized' );
echo 'Just the Admin can access, sorry.<br>' ;
echo '<a href="' . $_SERVER [ 'HTTP_REFERER' ] . '">Back</a>' ;
exit;
}
?>
it works, just that I have to retype 3 times user and password to reach to the
HTML Code:
Just the Admin can acess, sorry.<br>
<a href="" > Back</a>
please check here
http://positive0.negative0.net/tests/shop.php
let's say, I'm making a shopping mall. I'm going to add my products through this Admin mode. From the link I'm going to add products so that just me can add and no one else
Last edited by Michaelttkk; 01-25-2007 at 09:44 PM .
Learning never ends!
PHP Code:
<?php
$id = "user" ;
$pw = "password" ;
if ( !isset( $_SERVER [ 'PHP_AUTH_USER' ]) OR !isset( $_SERVER [ '$PHP_AUTH_PW' ])
OR $id <> $_SERVER [ 'PHP_AUTH_USER' ] OR $pw <> $PHP_AUTH_PW ) {
header ( 'WWW-Authenticate: basic realm="Admin Mode"' );
header ( 'HTTP/1.0 401 unauthorized' );
echo 'Just the Admin can access, sorry.<br>' ;
header ( 'Location: ' . $_SERVER [ 'HTTP_REFERER' ] ');
exit;
}
?>
the last one doesn't seem to work
but this works just that it doesn't show my index page instead it shows the auth.php's echo Just the Admin can access, sorry. [Back]
PHP Code:
<?php
$id = "user" ;
$pw = "password" ;
if ( !isset( $_SERVER [ 'PHP_AUTH_USER' ]) OR !isset( $_SERVER [ '$PHP_AUTH_PW' ])
OR $id <> $_SERVER [ 'PHP_AUTH_USER' ] OR $pw <> $PHP_AUTH_PW ) {
header ( 'WWW-Authenticate: basic realm="Admin Mode"' );
header ( 'HTTP/1.0 401 unauthorized' );
echo 'Just the Admin can access, sorry.<br>' ;
echo '<a href="' . $_SERVER [ 'HTTP_REFERER' ] . '">Back</a>' ;
exit;
}
?>
http://positive0.negative0.net/tests/index.php id=user pw=password
Last edited by Michaelttkk; 01-25-2007 at 10:26 PM .
Learning never ends!
PHP Code:
<?php
$id = "user" ;
$pw = "password" ;
if ( !isset( $_SERVER [ 'PHP_AUTH_USER' ]) OR !isset( $_SERVER [ '$PHP_AUTH_PW' ])
OR $id <> $_SERVER [ 'PHP_AUTH_USER' ] OR $pw <> $PHP_AUTH_PW ) {
header ( 'WWW-Authenticate: basic realm="Admin Mode"' );
header ( 'HTTP/1.0 401 unauthorized' );
echo 'Just the Admin can access, sorry.<br>' ;
echo '<a href="' . $_SERVER [ 'HTTP_HOST' ] . '">Back</a>' ;
exit;
}
?>
I'm going to do some changes with http://positive0.negative0.net/tests/index.php for a few seconds this result is without
PHP Code:
<?
include ( 'auth.php' );
?>
in index.php menu.php shopadd.php
Learning never ends!
but when i put the auth.php in all three pages
when I run the index.php the Admin mode appears
after 3 times of putting the id and password in tha admin mode it bring back to the page
Just the admin can access, Sorry.
Back
Learning never ends!
I think it's because of the frames.
alright now I'm gonna put the auth in the index.php menu.php shopadd.php
PHP Code:
<?
include ( 'auth.php' );
?>
Learning never ends!
I posted something that somehow didn't make it...
PHP Code:
<?php
$id = "user" ;
$pw = "password" ;
if ( !isset( $_SERVER [ 'PHP_AUTH_USER' ]) OR !isset( $_SERVER [ '$PHP_AUTH_PW' ])
OR $id <> $_SERVER [ 'PHP_AUTH_USER' ] OR $pw <> $PHP_AUTH_PW ) {
header ( 'WWW-Authenticate: basic realm="Admin Mode"' );
header ( 'HTTP/1.0 401 unauthorized' );
echo 'Just the Admin can access, sorry.<br>' ;
header ( 'Location: ' . $_SERVER [ 'HTTP_HOST' ]);
exit;
}
?>
I see this on the Admin mode
Admin Mode-1005
Learning never ends!
now, all error 404 document appear
Learning never ends!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks