0

I am creating a website for my organization that also has some web applications that run server side via CGI using Python. I am wanting a little bit more of a intuitive front end framework. I am also more familiar with Scripting languages then web languages. I have chosen Bootstrap as my frame work for it's user base and bound of documentation.

Now I am understanding the website authentication in regards to PHP and mySQL. But I have a question that I have not been able to find the answer to.

How do I set up website authentication via PHP and mySQL but not have every page end in .php?

For example is it possible to somehow insert this CheckLogin code at the beginning of but inside the html code of a webpage that is .html instead of .php:

<?PHP
require_once("./include/membersite_config.php");

if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("login.php");
    exit;
}
?>

The CheckLogin code:

function CheckLogin()
{
     session_start();

     $sessionvar = $this->GetLoginSessionVar();

     if(empty($_SESSION[$sessionvar]))
     {
        return false;
     }
     return true;

I am referencing this tutorial:http://www.html-form-guide.com/php-form/php-login-form.html

Update: I am using Apache.

I am looking for some guidance besides just the name of the technology, something with a example or tutorial as again I am very new to webside programming and I would benefit most from some real world type of examples.

EDIT: I am also looking for alternatives that would be best suited for CGI type of websites. Anything in the realm of Apache and website authentication based around integration with CGI.

This question was marked as duplicate but I disagree as it has more caveats do to the CGI nature instead of how to simply insert PHP into HTML. The most common solution found when researching "Web site Authentication" is PHP. Hence why asking how to make a CGI website turn by turning PHP pages into HTML pages for the sake of simplicity of using CGI. If there are easier ways to do this by all means please share.

BilliAm
  • 550
  • 1
  • 6
  • 23

2 Answers2

1

There's a few alternatives. One is to have Apache parse .html files as .php files by adding this to your .htaccess:

AddType application/x-httpd-php .html

Then you could simply add your script to the top of your .html files and it would work. However a cleaner solution would be to use mod_rewrite. For example, you could route www.example.com/page to www.example.com/page.php with

# .htaccess
# Enable Rewriting
RewriteEngine on

# Rewrite URLs
RewriteRule ^/(.+)/?$ $1.php

Or you could have one file as the router:

# .htaccess
# Enable Rewriting
RewriteEngine on

# Rewrite URLs
RewriteRule ^/(.+)/?$ index.php?page=$1

This version would pass whatever comes after www.example.com/ as a $_GET['page'] variable to your index.php file.

Note: I didn't test these, but they should work.

Here's a pretty nice tutorial for some more info: http://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708

Schlaus
  • 15,686
  • 10
  • 31
  • 62
0

as Halcyon wrote, it is not possible to combine your Authentification with .php and .html, because in .html you can't extract the session vars.

But as he wrote, you can use mod_rewrite to display the page not as ".php" but as ".html".

Regards Mike

Mike
  • 54
  • 1
  • 6