Apache: display properly logged in users (htaccess & htpasswd) information in all pages
Budget: €30 – €250 EUR
Hi,
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>
I use this code in wordpress header.php to show user login and password with some style when user logged in.
To check it you can visit this page: https://project.malemodels.tv/photos and use this login: web, password: web1.
When you login then you can see login information at top of page. It should be like this: Hello web. You entered web1 as your password. If you press Sign up then you also can see this information. Photos page created in wordpress and I added root/photos folder to secure site with htaccess and htpasswd. Now when you logged on all pages you are able to see “ Hello web. You entered web1 as your password. ” and this is correct.
When you logged out and visit this page https://project.malemodels.tv/ then you are not able to see full site like you are logged in, because in php code above I use “exit” function, it stops all scripts when logged out. But without exit message “Hello web. You entered web1 as your password.” only working on photos page, but in sign-up not (because sign up page do not have folder with htaccess and should not).
Main task: I need that logged out area shows all content of page like in logged in area and while logged in area visible I also need to show users information when they logged in, like this: “Hello web. You entered web1 as your password.” on all pages(home, sign-up, photos).
Now I am only able to show “Hello web. You entered web1 as your password.” on all logged in pages only if I have “exit” in code above and then logged out users will not see pages content, but they should see.
If I remove “exit” in code then all logged out pages will be visible like it should but in protected area only page “photos” will show this: “Hello web. You entered web1 as your password.” But other pages not, but I need it on all pages.
1. I need solution to show all content on all pages while ““Hello web. You entered web1 as your password.” Visible on all protected pages, also if there is no folder “photos” with htaccess, in our situation sign-up page also should show “Hello web. You entered web1 as your password.” .
I can remove exit code to show how It works: homepage working properly, but massage “You entered web1 as your password.” only visible in photos page, but should be visible at all.
Please help me figure out how to use this code or similar code to show on all pages for example users information or other information based on logged in status and keep website visible when logged out, but only pages like "photos" with htaccess should be protected.
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>
I use this code in wordpress header.php to show user login and password with some style when user logged in.
To check it you can visit this page: https://project.malemodels.tv/photos and use this login: web, password: web1.
When you login then you can see login information at top of page. It should be like this: Hello web. You entered web1 as your password. If you press Sign up then you also can see this information. Photos page created in wordpress and I added root/photos folder to secure site with htaccess and htpasswd. Now when you logged on all pages you are able to see “ Hello web. You entered web1 as your password. ” and this is correct.
When you logged out and visit this page https://project.malemodels.tv/ then you are not able to see full site like you are logged in, because in php code above I use “exit” function, it stops all scripts when logged out. But without exit message “Hello web. You entered web1 as your password.” only working on photos page, but in sign-up not (because sign up page do not have folder with htaccess and should not).
Main task: I need that logged out area shows all content of page like in logged in area and while logged in area visible I also need to show users information when they logged in, like this: “Hello web. You entered web1 as your password.” on all pages(home, sign-up, photos).
Now I am only able to show “Hello web. You entered web1 as your password.” on all logged in pages only if I have “exit” in code above and then logged out users will not see pages content, but they should see.
If I remove “exit” in code then all logged out pages will be visible like it should but in protected area only page “photos” will show this: “Hello web. You entered web1 as your password.” But other pages not, but I need it on all pages.
1. I need solution to show all content on all pages while ““Hello web. You entered web1 as your password.” Visible on all protected pages, also if there is no folder “photos” with htaccess, in our situation sign-up page also should show “Hello web. You entered web1 as your password.” .
I can remove exit code to show how It works: homepage working properly, but massage “You entered web1 as your password.” only visible in photos page, but should be visible at all.
Please help me figure out how to use this code or similar code to show on all pages for example users information or other information based on logged in status and keep website visible when logged out, but only pages like "photos" with htaccess should be protected.