Inject JavaScript using PHP - Stack Overflow

I would like to load external webpage using PHP and to inject some JavaScript to it before displaying i

I would like to load external webpage using PHP and to inject some JavaScript to it before displaying it.

To be honest, I have no idea at all how to do it (if it is possible). Somebody?

Example:

$html = file_get_contents($url);
// inject javascript here
echo $html;

I would like to load external webpage using PHP and to inject some JavaScript to it before displaying it.

To be honest, I have no idea at all how to do it (if it is possible). Somebody?

Example:

$html = file_get_contents($url);
// inject javascript here
echo $html;
Share Improve this question asked Oct 18, 2015 at 16:43 MenteMente 411 silver badge2 bronze badges 1
  • I would like to inject some JavaScript before displaying it? So like a XSS attack? – Nick Bailey Commented Oct 18, 2015 at 16:47
Add a ment  | 

2 Answers 2

Reset to default 3

you need to simply construct the string of your js code if it is for that page only and add it inside a script tag and echo the entire string. like this:

echo "<script>alert('hi');</script>"; //as page script example

Or if it is a file include then include it properly with script tag and echo it and it will be available on your page. like this:

echo "<script src='path to file'></script>"; 

In that case your code structure will bee like this

    $html = file_get_contents($url);
    echo "<script src='path to file'></script>"; 
   // echo "<script>alert('hi');</script>"; //as page script example
    echo $html;

simply echo it

$html = file_get_contents($url);
echo "your  javascript here"; 
echo $html;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745651016a4638264.html

相关推荐

  • Inject JavaScript using PHP - Stack Overflow

    I would like to load external webpage using PHP and to inject some JavaScript to it before displaying i

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信