SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Code:
    <?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();
    }
    ?>

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,836
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,836
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by multichild View Post
    Hi felgall,



    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
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    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.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Code:
    <?php
    $homepage = file_get_contents('http://www.example.com/');
    echo $homepage;
    ?>
    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 'http://www.example.com/' I'm guessing?

    Thanks for the idea

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Not silly at all!

    OK, your server path will be something like:
    (this is my dev server)
    Code:
    /home/devserver/public_html
    


    You can find out the document root and paths by using
    Code:
    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:
    PHP Code:
    $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
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah brilliant, thanks very much spikeZ.

    Thats great help cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •