2

I'm not sure why it should be, but index.html feels 'right'. I'm using index.php because if my login fails, I want to return to index.php and show the returned error on in the initial log-in page, like this...

<?php
   if(isset($_GET["loginFailed"])) {
      echo ($_GET['reason']);
   }
?>

That's trimmed a bit, but the 'reason' will be deciphered by the php and a user-friendly error shown.

The login error is just returned from my 'login.php' with something like..

if($row === false) {
    die(header("location:index.php?loginFailed=true&reason=usernamenotfound"));
}

This all works fine, but I have to keep the index named as index.php instead of index.html. If I change it to index.html, the php part is just ignored.

Is there anything wrong with my approach? Is it unsafe or anything?

4
  • 2
    Nothing wrong with index.php Commented Apr 14, 2016 at 13:51
  • 5
    Tis pretty standard to use index.php when developing with PHP. Though most sites nowadays will url rewrite so you wouldn't need / see the index.php or index.html anyway. Commented Apr 14, 2016 at 13:51
  • Cool. I'll look up what url rewrite is, but feel free to tell me here :) Would be nice if you didn't see the 'index.php' in the url I think. Commented Apr 14, 2016 at 13:59
  • And there's nothing wrong or unsafe about the url returning from login.php with something like .... http etc... / index.php?loginFailed=true&reason=usernamenotfound ? Commented Apr 14, 2016 at 14:02

1 Answer 1

4

No issue with using index.php instead of index.html. It does not affect search engine rankings - So the only reason you would want to change it is for aesthetics.

If you want to use index.html instead of index.php, there are two options:

Firstly, you can rewrite extensions using .htaccess. Add the following lines to your .htaccess, and they will remap all requests for a .html page to a .php one without the URL changing.

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

Secondly, you can allow .html files to be parsed by the PHP interpreter. To do this, add one of the following lines to your .htaccess (Different hosts have different syntax, the first works for most shared hosts)

AddHandler application/x-httpd-php5 .html .htm

AddType application/x-httpd-php .html .htm

AddHandler application/x-httpd-php .html .htm
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, may as well just use index.php then as it's much simpler. The url looks a bit messy when it returns with an error, but that's true of index.html too, e.g it returns with something like index.php?loginFailed=true&reason=usernamenotfound . But if it's not a problem, it's not a problem :)
@Farflame you can use session() and the url will look "nice". Basically you set a variable that is valid even if the user change page, or go back to index.php
Ah yeah, session(), I did use that before for something so shouldn't be too difficult. I'll look into that, thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.