/    Sign up×
Community /Pin to ProfileBookmark

How to run PHP outside document root via javascript?

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 :

[code=php]
<?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>
[/code]

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

[code=php]
<?php
echo “<h3>I’m here!</h3>”;
?>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@TheRaveJan 18.2008 — 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.
Copy linkTweet thisAlerts:
@bathurst_guyJan 18.2008 — TheRave is correct, JavaScript cannot. PHP can include from another file in another location though.
×

Success!

Help @ploceus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...