I'm brand new today to using PHP but I can't get anything showing on the page. I've installed XAMPP, started the server, mounted the volume and created a new file, index.php, which I've moved into a new folder called scripts inside htdocs. Based on the articles I've been following this should give me output at localhost/scripts/index.php but it is only giving me the 'requested URL not found on this server' response (I'm just running a basic echo 'hello world' line). Thanks for any help.
Going to just http://localhost shows the 'It works!' message but nothing else.
Check if there are any processes running on port 80, if you have skype or torrent client please close them and try restarting xampp.
Also check if it running on your IP Address. open command prompt and type ipconfig for windows and ifconfig for mac.
once you get your ip address type it in the browser and see if you can find the server running.
Try to save the file with correct extension i.e. .php just typing .php at the end sometimes doesn't work.
Try to do this,
1. Add double inverted commas ""
2. File Save as Type - All Files
3. add .php at the end of your filename
Related
When I open my Linux terminal and type the following command:
rsync server_name.xxx.com:/directory_name
It works perfectly, the information of the file is shown on the screen.
However, when I put the command in a php file like this:
$variable='rsync server_name.xxx.com:/directory_name';
$output=shell_exec($variable);
echo $output;
Nothing shows up on the browser. Trust me, I have do the Google search for several hours, and find no clue. How can I know if a file locates at another remote server exist (readable) or not without logging on that server?
Any suggestion? Thanks a lot!
You want the file_exists function. Documentation: http://php.net/manual/en/function.file-exists.php
I am trying to execute a php file from sos-berlin jobscheduler. My OS is windows 7. I am following the documentation
http://www.sos-berlin.com/mediawiki/index.php/How_to_execute_a_PHP_script_with_JS
#!/usr/bin/php
<?php
echo "hello";
?>
But when I executed the script I am getting the error that
'#!' is not recognized as an internal or external command, operable program or batch file.
I came to understand that #!/usr/bin/php is a linux command. I should give here equivalent batch command. I googled, but didn't find any useful result. Please any one help me...
Thanks in advance.
Suppose you have installed php.exe in C:\Program files\MyPhpProgram\php.exe
Then run below 2 lines on terminal (cmd.exe):
assoc .php=phpfile
ftype phpfile="C:\Program files\MyPhpProgram\php.exe" "%1"
Go to your desktop.
Right click My Computer shortcut in the desktop.
Click Properties.
You should see a section of control Panel - Control Panel\System and Security\System.
Click Advanced System Settings on the Left menu.
Click Enviornment Variables towards the bottom of the window.
Select PATH in the user variables list.
Append your PHP Path (C:\myfolder\php) to your PATH variable, separated from the already existing string by a semi colon.
Click OK
Open your "cmd"
Type PATH, press enter
Make sure that you see your PHP folder among the list.
That should work.
install a php engine on windows
in a cmd windows for example, run php <path/to/your/script>
open cmd, go to where you installed php. and run c:\program files\php\php.exe <path/to/your/scirpt>.php
link to setting up the path to include php so you can run it easily from cmd:
http://willj.co/2012/10/run-wamp-php-windows-7-command-line/(dead link)
I have been trying unsuccessfully so far to write a php script that will run when a page is opened and that will launch metasploit!
I ve tried shell_exec and exec and all the other alternatives but although I can get it to do simple things (i.e. ls, cds etc) if I try msfconsole it doesnt do anything!
I have also tried a different script that launches firefox and again nothing happens!
Now i know that php runs on the server and I m not expecting to see a console or firefox opening in the clients machine! Instead in order to check if it works I am trying to echo out the output of the shell_exec!But anyway since im hosting the files on my machine (i.e. this is the server and a VM is the client) if it could actually launch firefox i should be able to see the app opening here in the same way as by just doing this from the command line!
What am I missing?
Is there any other way to do this?(i.e. Launch metasploit everytime a user opens up my page)
NOTE: I've tried specifying the full path for msfconsole but that didnt work either!
Heres what I have so far:
$output = shell_exec('/opt/local/libexec/metasploit3/msfconsole;show');
echo "<pre>$output</pre>";
The ";show" bit was used in order to actually make it run something and print some stuff but didnt make any difference!
When you run a gui application from the command prompt in a X window system, it will use the default display. When you run it using php which is embedded in apache webserver, the program may not know where to display the gui application.
there are 2 things to make this work.
The program that executes the gui application must have permission to use display
you need to tell the program which display to use.
I used the following in my php script
<?php
$cmd = `export DISPLAY=:0; gedit`;
shell_exec($cmd);
?>
and ran the script from terminal using php -f test.php
I got the gedit up and running.
You can test the same with the script in apache too.
Please add apache user with privileges to access display server
update: I just added the following in /etc/apache2/apache2.conf (I am using ubuntu)
User poomalai
Group poomalai
and restarted the web server
sudo service apache2 restart
now I accessed localhost/test.php
and Presto!! I got the gedit :)
Hope this helps
I have mapped a network drive to a computer in my home network. Now I am trying to access it via PHP - I did this quick test:
echo opendir('Z:\\');
This gives me:
Warning: opendir(Z:\) [function.opendir]: failed to open dir: No error in C:\wamp\www\webs\tester-function.php on line 3
What have I done wrong here?
I don't want my users typing in the UNC path so is there a way to get the UNC path for them and maybe that will work when I try to access it? This is possible in Microsoft languages but I am not sure how to get PHP to do this - maybe using a cmd.exe command?
Please note, the mapped drive does exist as I can see it and I can access it. It also does not appear to be a permissions problem as I am assuming it would of complained about this IF it could access that drive...right?
Thanks all for any help
The User Contributed Notes to opendir() have this:
I was trying to access network drives using this opendir function. I read so many posts saying that it was almost impossible to access a network drive and finally, I found the answer; there are 2 steps to be followed to access a network drive with PHP either on the same machine or another machine.
in this case, the user rights seemed indeed to be the problem, which can be different from your rights depending on what user PHP / the web server are running on.
Open the Services MMC by going to Start -> Run (or by using the search box, if using Windows 7) and typing Services.msc and pressing enter.
Find the Apache service. Having never used WAMP, I have no idea what it's been named. Hopefully it starts with the word "Apache" though, and thus shouldn't be too hard to find.
Right-click on the service and select Properties.
Switch to the Log On tab.
Select the radio button next to "This account:" and enter in the credentials for the user account you want to run Apache under. If it's a network/domain account, use the "DOMAIN\user" syntax (or search for the account using the Browse button).
Select OK and restart the Apache service.
Verify that your changes worked by looking for the "httpd.exe" process in Task Manager and checking to see which user name the process is running under.
reference http://board.phpbuilder.com/board/showthread.php?t=10371870&page=2
simple, use: "\\\\server\\dir\\subfolder" as the path. make sure you can access the "server".
works for me.
$arquivo = "\\\\server\\dir\\subfolder\\file.txt";
echo is_file($arquivo); //print 1.
I have a PHP script that calls a .bat file using system(). The output is written to the screen and I derive some values from parsing this output. This is running on windows 2003 IIS server. PHP v5.2.0
Specifically I am using this script to launch an Amazon EC2 instance and assign an IP address to it. It has worked great for me so far but recently the problem started.
Here is the code
$resultBatTemp = system("cmd /C C:\Inetpub\ec2\my_batch_file_to_launch_instance.bat");
$resultBat = (string)$resultBatTemp;
$instanceId = substr($resultBat, 9, 10);
...
Once I have this instace Id I can run another batch file that calls associates an ip address with this instance. It would appear that the instance does get launched but I never get the output on the screen.
For some reason this has all stopped working, the page freezes and never refreshes. I also need to completely exit safari or mozilla otherwise all pages from the website fail to load. Only when I relaunch the browser can i view the website again. I've connected to the webserver that hosts these scripts and checked PHP error log but nothing shows there. I've opened a DOS prompt and entered the code from the bat file that way and it connects to amazon and launches the instance fine. Ive isolated this bit of code and removed the system command and the rest of the script runs fine, so it appears that the hold up is with outputting the results of the bat file.
Recently I have purchased a new domain name for the site so this script is running from this domain. Might this cause the problem?
thanks
------------------------------------------------UPDATE-----------------------------------------------
Well hope this helps someone, I didnt find out what was wrong but created a new PHP file with a simple system command that called a .bat file, and a non-existent .bat file expecting to get an error back but nothing - just the usual hang for ages. So I restarted IIS and this fixed the problem. Dont know what was wrong but that did the trick.
Maybe first check what the system() call returns. According to documentation it will return FALSE in case of failure. Also, including your my_batch_file_to_launch_instance.bat in the question might help in solving it.
Try using the passthru function
Also make sure that all your commands are safe use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands.