最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php cron job execute javascript as well - Stack Overflow

programmeradmin2浏览0评论

I have a cron job running a php script, but theres some html and javascript that I need to execute for the actual script to work.

Converting the javascript to php isnt an option.

Basically I need it to act as though a person is viewing the page every time the cronjob runs.

EDIT: the script uses javascript from a different site to encrypt some passwords so it is able to log into my account on the site, and the javascript is thousands of lines. The way the script flows is: Send data to website>get the data it sends back>use sites javascript to alter data>set html form value to value of data returned by javascript function>submit html form to get info back to php>send data to log me in. I know the code is very shoddy but its the only way i could think to do it without having to rewrite all the javascript they use to encrypt the password to php

I have a cron job running a php script, but theres some html and javascript that I need to execute for the actual script to work.

Converting the javascript to php isnt an option.

Basically I need it to act as though a person is viewing the page every time the cronjob runs.

EDIT: the script uses javascript from a different site to encrypt some passwords so it is able to log into my account on the site, and the javascript is thousands of lines. The way the script flows is: Send data to website>get the data it sends back>use sites javascript to alter data>set html form value to value of data returned by javascript function>submit html form to get info back to php>send data to log me in. I know the code is very shoddy but its the only way i could think to do it without having to rewrite all the javascript they use to encrypt the password to php

Share Improve this question edited Feb 12, 2012 at 15:36 Max asked Feb 12, 2012 at 15:15 MaxMax 592 silver badges7 bronze badges 6
  • 8 How exactly does one execute HTML? What are you specifically trying to acplish in your cron job? Because it seems like you may be going about this the wrong way. Give us a little more information about your intentions and you'll probably get a better solution. – user895378 Commented Feb 12, 2012 at 15:16
  • 1 What's wrong with converting it to PHP? Surely if the javascript must be called, then it calls a PHP script somewhere? – Westie Commented Feb 12, 2012 at 15:18
  • the script uses javascript from a different site to encrypt some passwords so it is able to log into my account on the site, and the javascript is thousands of lines. The way the script flows is: Send data to website>get the data it sends back>use sites javascript to alter data>set html form value to value of data returned by javascript function>submit html form to get info back to php>send data to log me in. I know the code is very shoddy but its the only way i could think to do it without having to rewrite all the javascript they use to encrypt the password to php. – Max Commented Feb 12, 2012 at 15:29
  • I think this is a very interesting question. – Toby Allen Commented Feb 12, 2012 at 15:30
  • 1 @Max, update your question rather than posting a ment. – Toby Allen Commented Feb 12, 2012 at 15:30
 |  Show 1 more ment

3 Answers 3

Reset to default 6

Yau can try Node.JS to run JavaScript code on the server.

install your favorite web browser, and then have the cron job run the browser with the url as an argument.

something like

/usr/bin/firefox www.example./foo.html

you'll probably want to wait a minute or so and then kill the processes, or determine a better way to find when it finishes.

cronjobs always runs on server side only. when there is no client side - how can you expect javascript to work really???

anyway solution is: use cronjob to run another php script - which in fact calls the php script you want to run using CURL. e.g. file1.php - file you want to execute and expect the javascript on that page to work.

file2.php - another file you create ... in this file use curl to call the file1.php ( make sure you provide full http:// path like you type in browser - you can pass values like get/post methods on html forms do as well ). in your cronjob - call file2.php.

Make sure curl is available and not any firewall rule blocking http calls i.e. port 80 calls to same server. Most of the servers both conditions above are fulfilled.

---------- sorry guys - Kristian Antonsen is right - so dont consider this as full answer at the moment. However I am leaving this on as someone might have food for thoughts from this -----

发布评论

评论列表(0)

  1. 暂无评论