简体   繁体   中英

Run php script from URL in command line

Can I run a php script from command line with the following usage:

php http://phpfile.php username password config_file

When I run this it says cannot open input file http://phpfile.php

If there is what would be the best way to execute this within a php script?

Thanks

This is practically not possible . You cannot execute a php script hosted on someone else's server in your cli.

WHY?

Consider this case. Facebook has a php script which adds a comment to the database. So What would be the outcome if someone executes this script from local command line, and goes about adding comments to the database ? This would really mess up the systems. Or consider something like a file hosting script. You can very well imagine the outcomes if anyone can delete any file from their own cli.

Solution!

The file can be executed if:

  • Either you have the script saved locally and run it
  • Or make a get or post request to script with required data and make it do stuff.

Summing up

You can execute it only if the owner allows it (via get and post requests)

Refer these

Do a post request using Guide to making requests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM