0

My problem is this: The website cannot access the index.php script file. It will not access it by default. It will not access it if I type it explicitly. I can, however, access the login.php script file which is contained in a different directory. here is the contents of the .htaccess file

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php

Here is the first 11 lines of the /public_html/index.php script file:

<?
session_start();
echo 'index start';
exit;
include $_SERVER['DOCUMENT_ROOT'] . 'library/library.php';
if($_SESSION['logged_in'] === 'TRUE'){
//nothing....
}else{
$_SESSION['logged_in'] = 'FALSE'
}

The support personnel at bluehost said that there is an error on line 11 with a }. (forgive me, I forgot to copy the error exactly.)

I'm not a complete novice at PHP. I understand that the exit; on line 4 should prevent this error from happening. I am at a complete loss.

Kyle Birch
  • 75
  • 1
  • 10
  • Its been ages since I have done any php but don't you need to close the script with ?> – paul May 14 '15 at 05:40
  • 1
    Just a missing semi-colon in your else clause – Hanky Panky May 14 '15 at 05:41
  • 1
    no @paul, in fact people recommend not to use `?>`, and i still don't why. :) – Jigar May 14 '15 at 05:42
  • Like I said before, nothing after line 4 should be executing, so if you aren't at least answering that problem, I can't honestly consider your critique of my code in lines 5-11 worth paying attention to as I try to solve this problem. – Kyle Birch May 14 '15 at 05:42
  • No @KyleBirch i'm sorry your understanding is incorrect. If there is a parse error even on line 2000000 and you have an exit on line 2 it wont work. Your have to fix the parse error first otherwise that `exit` as well as any other good code is meaningless. – Hanky Panky May 14 '15 at 05:42
  • @paul http://stackoverflow.com/questions/4410704/why-would-one-omit-the-close-tag – Tuan Anh Hoang-Vu May 14 '15 at 05:43
  • Thanks @tuananh - Told you its been ages – paul May 14 '15 at 05:44
  • Thank you for that. Is there a way to prevent anything else from being parsed past a certain point? – Kyle Birch May 14 '15 at 05:45
  • @KyleBirch: You assume the exit prevents the rest of the code from being parsed, which is false. PHP *must* parse the whole file before executing the first line. You could use [`__halt_compiler()`](http://php.net/manual/en/function.halt-compiler.php) to achieve what you want. Godspeed. – vstm May 14 '15 at 05:45
  • I FINALLY understand my real problem. The local development environment I am used to had different settings with executing code when errors are found, and different settings for displaying parsing errors. It makes more sense now. Thank you soo much everybody. – Kyle Birch May 14 '15 at 05:48

1 Answers1

0
<?
session_start();
echo 'index start';
exit;
include $_SERVER['DOCUMENT_ROOT'] . 'library/library.php';
if($_SESSION['logged_in'] === 'TRUE'){
  //nothing....
}else{
  $_SESSION['logged_in'] = 'FALSE';
}

Notice the ; in else condition.

Jigar
  • 3,256
  • 1
  • 30
  • 51
  • @jQuery.PHP.Magento.com i highly doubt it. we can skip the `{`&`}`, not the `;` in case of single line. – Jigar May 14 '15 at 05:46