i need some help with php code, i need a code that will check the users username?

  • Thread starter Thread starter James B
  • Start date Start date
J

James B

Guest
ok so if a user1 signed into his own page, he would have the url mysite.com/user1/index.php, but if he changes this to mysite.com/user2.index.php he can access user2's stuff. so i need a small code that will check a users username and if it dose not match a set username, redirect them to mysite.com/index.php. any help?
Thanks for the help but i came up with this solution

<?
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}

if ($_SESSION['myusername']=="username here")
echo "";
else
header("location:some page");
?>
 
User registration is a relatively complex issue.

Go here for a tutorial which I think meets your needs:

http://thybag.co.uk/index.php?p=Tutorials&ind=38

This uses basic authentication without a MySQL database (which you didn't specify you had).

If you do have a MySQL database, you might be better using this method:

http://www.php-mysql-tutorial.com/wikis/php-tutorial/basic-user-authentication.aspx
 
Back
Top