开发者

need to inject the output of a javascript into a php script; is this possible?

both codes can be also seen side by side at panelbackup(dot)com/codes

ok, so I have this code located on page 1.html which appends 4 random numbers after the given url :

<head><script>window.onload = function() {
        var links = document.links;
        for(var h in links) {
                var rand = Math.floor(Math.random() * 10000);
                links[h].href += (links[h].href.indexOf('') == -1 ? '?' : '')+''+rand;
        }
}
</script>
</head>


<a href="http://panelbackup.com/blahblah">randomURL</a>

and I then need to inject or call this into the following php script:

<?php
$a=fopen('http://output from javas开发者_高级运维cript','r');
$b = stream_get_contents($a);
echo $b;
fclose($a);

any ideas on how this could be accomplished? the php script is on 1.php and the javascript is on 1.html located at panelbackup(dot)com


In your JavaScript why don't you set the random number as a named parameter and then access it from PHP the same as any other request parameter?

links[h].href += (links[h].href.indexOf('?') == -1 ? '?' : '&')+'newParam='+rand;

This will change the link to be

<a href="http://panelbackup.com/blahblah?newParam=153">
or
<a href="http://panelbackup.com/blahblah?existingParam=whatever&newParam=153">
(assuming the random number is 153)

Note: your code was testing for a '?' in the existing url and adding one if not found, but you need to add an ampersand if '?' was found or your random number will end up concatenated to the end of the existing parameter's value.

EDIT: PhpMyCoder's suggestion to generate the random numbers on the PHP side is a better way to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜