/    Sign up×
Community /Pin to ProfileBookmark

Javscript inject

Hey,

Quick question – is it possible in javascript to use some kind of injection into php so that it will count as php rather than a string?

Here is what i mean:

I have a JS file which loads content of a php file in a div specific place.. for example on

index.php

i have
<a href=”javascript:ajaxpage(‘home.php’,’contentarea’);” >Home</a>

Then the div named contentarea is populated with the home.php

How ever i want to change this so that the content area infact gets populated with a string which shows:

[CODE]
<div name=”contentarea”>
<?php
include(“home.php”);
?>
</div>
[/CODE]

If you see the connection here:
the href has the “url” then div name

And so in div content i want to pass the “url” into the php ? That make sense ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorDec 08.2009 — 
Quick question - is it possible in javascript to use some kind of injection into php so that it will count as php rather than a string?
[/QUOTE]

No. javascript can not interfere with php in that way.

Anyway, what you try to do is HTML illegal. You can not nest a whole document into a div. You could use an [B]iframe[/B], but I don't see the point of.
Copy linkTweet thisAlerts:
@aj_nscDec 08.2009 — Of course it's possible using javascript, specifically Ajax.

What you need to do is to make an Ajax call to home.php and in the response will be the output of what home.php would look like after it's been run through the php parser.

Then all you have to do is set the Ajax response as your innerHTML of your content div and bingo, you've achieved your desired effect.

There's quite a few potential issues associated with this method, but we'll leave explaining them to a point in the future if the issues arise.

I think what Kor meant, which is perfectly valid, is that home.php can't contain things like body or head tags, for example. Even then, you could still parse your responsetext.

Google Ajax and find some examples. The effect can be achieved, you just have to use your imagination.
×

Success!

Help @SirChick 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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