jennhazy Posted November 7, 2019 Share Posted November 7, 2019 Hi everyone - I am trying to figure out how I can allow my logged in users to leave a php page and go to an html page without losing them as "currently logged in" - I have a site that is mixed with html and php pages and this is what I am needing: i have a user, they are logged in and are visiting a php page. then they want to go to another page(only logged in users can access the php page) - so they click on the html page they want to go to, great! - but then they want to visit another page that is a php page and requires them to be logged in in order to access it. How can i accomplish this without having them log in yet again? is this possible? i am using sessions. Quote Link to comment https://forums.phpfreaks.com/topic/309476-how-to-go-from-php-to-html-without-losing-login/ Share on other sites More sharing options...
gw1500se Posted November 7, 2019 Share Posted November 7, 2019 (edited) Use sessions. Each page will need to check a session variable to determine if a user is logged in. If so deliver the page, if not deliver the login page or an error. Edited November 7, 2019 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/309476-how-to-go-from-php-to-html-without-losing-login/#findComment-1571311 Share on other sites More sharing options...
gw1500se Posted November 7, 2019 Share Posted November 7, 2019 (edited) I failed to mention that if you have admin privileges you can create rewrite rules that protect the directory containing member only pages. But that is not a pure PHP solution but rather an httpd configuration solution. Edited November 7, 2019 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/309476-how-to-go-from-php-to-html-without-losing-login/#findComment-1571316 Share on other sites More sharing options...
Zane Posted November 8, 2019 Share Posted November 8, 2019 First of all, PHP and HTML are two separate things altogether. PHP is typically used to generate HTML. No matter what language you use, when you load a page in a web browser it's source will be pure HTML (and/or even JavaScript). In PHP, the way to preserve a session on every page is to call this function before the first time that you use any $_SESSION variable or anything session related. session_start(); There's no "html page" or "php page". There is just a file that a browser reads the best it can depending how the server reads the extension of the file. So, in order to accomplish the problem of "keep my users logged in on an html page", you need to have PHP file that checks for the session's existence and resumes it if it exists. If it doesn't exist, then it starts one. Correct me if I'm wrong, but I get the feeling when you refer to a "php page", you're referring to the extension of the file ..? mypage.html vs mypage.php Quote Link to comment https://forums.phpfreaks.com/topic/309476-how-to-go-from-php-to-html-without-losing-login/#findComment-1571333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.