Click to See Complete Forum and Search --> : How to run PHP outside document root via javascript?


ploceus
01-17-2008, 05:10 PM
I'm trying to run PHP script that is outside the document root for security
reasons but it's not working. Document root is /var/www/html. Application will be in /var/www/app directory.

What should I do to javascript part to access foo.php?

Thanks.

index.html :

<?php
session_cache_limiter('private');
session_start();
?>

<html>
<?php
echo '<input id="button" type=button name="do" value="Click here" onclick="do_foo()">';
?>
</html>

<script type="text/javascript">
function do_foo()
{
window.location.href = "../app/foo.php";
}
</script>


In /var/www/app/foo.php :

<?php
echo "<h3>I'm here!</h3>";
?>

TheRave
01-18-2008, 02:37 AM
Javascript is a client side language and therefore it can only access items that the client can access. Since the client cannot directly access anything outside of the document root Javascript cannot either.

bathurst_guy
01-18-2008, 02:43 AM
TheRave is correct, JavaScript cannot. PHP can include from another file in another location though.