admin管理员组文章数量:1026670
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
2 Answers
Reset to default 3you 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;
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
2 Answers
Reset to default 3you 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;
本文标签: Inject JavaScript using PHPStack Overflow
版权声明:本文标题:Inject JavaScript using PHP - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745651014a2161318.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论