Jump to content

Access php with specific username


ananaz

Recommended Posts

Hello

Im trying to make a php that only will be accessible for a specific user for example "admin"

 

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
else {
if(!myusername == 'admin'){
header("location:index.php");
}
else {
echo "Välkommen ". $_SESSION['user'];
}
}
?>

 

index.php is the mainpage you get thrown back to if session is not registered or if myusername isn't admin (tho it doesn't work)

 

Link to comment
https://forums.phpfreaks.com/topic/222675-access-php-with-specific-username/
Share on other sites

Your code:

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
else {
if(!myusername == 'admin'){
header("location:index.php");
}
else {
echo "Välkommen ". $_SESSION['user'];
}
}
?>

 

session_is_registered is deprecated.

Now new version for your script:

<?php
session_start();
if(!$_SESSION['myusername']){
header("location:index.php");
}
else {
if($_SESSION['myusername'] != 'admin'){
header("location:index.php");
}
else {
echo "Välkommen ". $_SESSION['myusername'];
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.