Is it possible to make a php code on a webpage send out a code that the visitor will run? Like:
<?php
batch("echo text");
?>
Then it will open a cmd window that says text. If it does not work in php does it work in another launge?
PHP runs on a server and has no magical control over what happens on someone else's computer. Once the page has loaded it will be send to the requester's browser.
From there you have access to some local storage/cookies/etc., but only what the browser provides to you. If the browser would give a website access to the cmd, it would mean that any website could simply read pretty much everything on anyone's computer, or do harm in many other ways. You can imagine that this is not really secure.
The only way you can execute batch commands on someone's computer is if you or your program have access to that computer. In other words, the user must download your batch/.exe file and run it manually.
Related
I believe my goal should be sort of simple, but being somewhat new to server admin I am coming to a halt. My goal, be able to execute a .bat file located on one of my remote servers by clicking a button on a page in the Admin section of my website. My website is hosted on one server and the the .bat file is hosted on a 2nd server. The two machines serve very different purposes so combining them is not viable.
I have seen fopen, exec, and a couple other PHP methods but I am either not implementing them correctly or they are not the correct approach to use in the first place.
Say that the server with the .bat file is at IP address 200.100.100.1
Say my website is hosted at 100.100.200.2
The .bat file I am trying to execute (for example) would be something like this:
#ECHO OFF
echo Hello, World.
pause
I have searched around quite a bit and have either not been asking my question correctly, or perhaps this is not possible to do at all (I have a hard time believing no one has asked this question before).
Thank you to all in advance.
I have a script which logs you into zencart when you open it in your browser.
Now when I try to call this from inside another php script using require, header, or curl, it does not login to zencart. It only works when the user opens the php script directly in their browser.
I also tried virtual(), but its running the index.php script for the top level of the site, not the file I specify. Thanks.
I got this working by reading the session from the database. Let me know if anyone is interested and I will open up a github. Thanks!
Does anyone know if it is possible to send a command line script from a php page to another server from which the php file is not on? So Php file is on server A and the command line script needs to be run on server B. Both are hosted locally but on seperate machines.
I dont think it is possible but just want to see if anyone else has tried it or knows it doesnt work either.
Thanks,
Mike
It is possible to make a PHP script log on to another server using SSH, but it's very complicated.
It's probably much, much easier to have a publicly accessible PHP file on the remote server, call that through the web, and have it perform whatever actions you need.
What you describe can be done as a a simple "REST service" which Pekka described.
You should also research "RPC" (Remote Procedure Call) and "SOAP" as well.
Both of those come with some baggage, and both are probably overkill, but they are solutions to the problem.
Im here to ask a probably dumb question again. This is related to my previous questions.
I current found a way for flash/flex to send a video file(in byteArray) to php. Where php receives and writes it in the local sytem then sends it to the youtube server automatically trhu a script.
This is all backend though I have no way to check if the video file was uploaded succesfully in youtube than to check it manually in youtube.
So im thinking of a new php script where it will receive and write the video file from flash. Then opening a browser window where it will automatically upload the video and at the same time track it thru the browser of its status using debug prints perhaps.
Im barely still learning php. I tried to do some research on this but found no success. Hope you can help me guys. Thanks.
PHP code runs on your web server. It's code running on another computer. It can't open anything on YOUR computer. If it could, I would also be able to open windows on YOUR computer from the one I'm typing on, and you'd have some serious problems. By tomorrow everyone in the world would have their computers either taken over or destroyed by other random people on the internet.
PHP is server side, you can't directly use any PHP code to control browser activity on client side.
You need to resort to client side technology such as Flash and JavaScript.
echo "XXX window.open('URL');XXX'
XXX = script tag from Java, I can't post html tags
I am trying to create a script that will display the contents of a folder, onto a newsticker, and I was wondering if anyone had a script that could run this. I was thinking probably php, but it has no been working for me.
Thanks for the help
The software I am using is dreamweaver cs4
I'm guessing that you have written some PHP, but are trying to run it locally without a server - for PHP to work you need a server. XAMPP is a good bet to do this locally, or you'll need to upload your file to some hosting that supports PHP.
I'm thinking why you're having trouble with it is because you just copy and pasted the code in a .html file and opening it on your local environment.
With that said, in order for it to run locally, you have to install php and a http server. The code is done on server side, not client side. So either get a hosting service that supports php or download and install your own server and php.
Also, if you already have the above, the code has to be surrounded by a < ?php and ? > tags(without spaces). If you're running it on cli, then you need to make sure you give it execution permission with the path to php, OR execute php < name of script >.
Last, the code you presented provides major security flaws. The first of which is where will the "$dir_path" variable be set? Will that be user given, or will you specify the variable?
Whenever you allow users to view your file system, always make sure you give limitations to it. For example, let's say you did this:
www.example.com/newsticker.php?path=/www/files/newsticker
looks innocent enough, but a clever hacker could say let me try....
www.example.com/newsticker.php?path=/
And so fort.
So be careful and don't allow users to specify directories or execute code.