Forum Moderators: phranque
My proble is that I have 1500 static pages in html format & I want to show it to user through login system & I want to track that user is logged in on every HTML page he/she visit.
I am using php as server side scripting, but problem is that I have lots of Static HTML Page so I can't Make any changes in that pages.
Is there any idea to track user on static HTML pages.
In other way I just want that anybody who has not logged in won't see my HTML Page. I dont want to use .htaccess files.
Any Idea?
Navin
I am using php as server side scripting, but problem is that I have lots of Static HTML Page so I can't Make any changes in that pages.
You could add some php user validation by adding a single line to the very top of each of these pages. Something like..
<?php require_once 'user.php'; restrict_page()?>
and then in the user.php file you would have a function like this..
[pre]
/**
* Only logged in users can view this page.
**/
function restrict_page() {
if (!isset($_SESSION['loggedIn'] or!$_SESSION['loggedIn'] ) {
header( 'Location: http://yoursite.com/login.html' );
exit;
}
}
/* Start session when this file is included */
session_start();
[/pre]
This function redirects users who are not logged in to a login page.
To avoid changing all your .html pages to .php you can make Apache treat html files as php, by editting you httpd.conf file and changing the line
AddType application/x-httpd-php .php .phtml
to
AddType application/x-httpd-php .php .phtml .html
Thats just the basics.
Obviously you'll need some code to allow your users to login and set the $_SESSION['loggenIn'] variable to true - but I'm not going to write the whole system for you ;)
There are loads of examples of systems like this, try this one from SitePoint [sitepoint.com].