Change php script to jscript

I am in the process of adding modules to a website that have been provided to me and because of the way its set up they are .html files, and they exist within my system which works with php.

As they need to be secure I need to add the following script which is in php to the page, so I thought there might be away of doing the same sort of check but instead with jscript so I can put it to the top of th epage to make it secure.


<?php
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID_2']) || (trim($_SESSION['SESS_MEMBER_ID_2']) == '')) {
header("location: index.php");
exit();
}
?>

jScript only runs in Internet Explorer 9 and earlier.

There’s no equivalent to that PHP code in either jScript or JavaScript as it is something that must be run on the server.

The best solution would be to configure your server to allow it to run PHP on all the .html pages so you can add the code there. If your site is running on Apache then you just need to add one line to the .htaccess file to do this.

AddHandler application/x-httpd-php .php .html

Hi felgall,

[QUOTE=felgall;5613084The best solution would be to configure your server to allow it to run PHP on all the .html pages so you can add the code there.[/QUOTE]

This seems the best solution, so basically I can then just add the php in as normal at the top of the page, and that will allow it to run.
Cheers

Yes

Typical,

Just contacted the hosting company and they do not support Php Parsing.

Am going to have to think of another way now, as these .html files cannot be accessible without logging in.

I could use an iframe perhaps inside a .php file and draw it in that way.

put them above the webroot so they aren’t accessible by a browser and use php to read and display them
file() or flile_get_contents() would do.

Right OK, so put all those .html files above the root level, and then when calling them, link the link the users uses to see them, to a new .php page with at the top of the page.


[FONT=Courier New][COLOR=#0000BB]<?php
$homepage [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]file_get_contents[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'http://www.example.com/'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]);
echo [/COLOR][COLOR=#0000BB]$homepage[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];
[/COLOR][COLOR=#0000BB]?>[/COLOR][/FONT]

And the echo will pull the file in is it?

Sorry to be a little silly hear too, but how do I call files outside the root level instead of [COLOR=#DD0000][FONT=Courier New]‘http://www.example.com/[/FONT][/COLOR]’ I’m guessing?

Thanks for the idea

Not silly at all!

OK, your server path will be something like:
(this is my dev server)


[COLOR=#000000]/home/devserver/public_html
[/COLOR]

[COLOR=#000000]

You can find out the document root and paths by using
[/COLOR]


echo '<pre>';
print_r($_SERVER);
echo '</pre>';
?>

That gives you the DOCUMENT_ROOT - [DOCUMENT_ROOT] => /home/devserver/public_html
(it could also be something like var/www/)

The part you need is before the public_html
/home/devserver/

Then use:


$filename = 'hub.html'; // which file you are retrieving ABOVE the root
$file = '/home/devserver/'.$filename.'';

if(file_exists($file)){
    $f = file_get_contents($file);
    echo $f;
} else {
    echo 'fail'. $file;
}

Basic example but gives you the idea :slight_smile:

Ah brilliant, thanks very much spikeZ.

Thats great help cheers