Jump to content

In need of a little help.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
14 replies to this topic

#1
Jack-ClansVoice

Jack-ClansVoice

    Newbie

  • Members
  • Pip
  • 6 posts
NOT NECESSARY:
I have recently been learning PHP, in doing so one of my friend who already knows PHP told me that the best way to learn, is to work on a project. So I went on a mission to make a basic control panel. This control panel has the basic features, the ability to view server files, stop start and restart the server.

NECESSARY:
Alright, here is the important information. I am using Windows 7 with WAMP, (Apache, phpMyAdmin etc.)

The contents of the PHP starting script:
<?php

if(isset($_POST['submit']))

{

echo exec('start_srv.bat');

echo "Server started, this may take a few seconds.";

} else {

?>

<form action="" method="post">

<input type="submit" name="submit" value="Start">

</form>

<?php

}

?>

The contents of the batch file (start_srv.bat):
(example purposes only)

START NOTEPAD.EXE


Now, when I click the 'Start' button the page just loads and does not execute the batch file which would usually run notepad (or when it gets serious, the server cmd file).


Without further adieu, my second problem.

The index/main code file.
<form action="saves/rsave.php" method="post">

<textarea name="save" rows="25" cols="75">

<?php

         include("c:/Users/Jack/Desktop/ventrilo/ventrilo_srv.rank");

 ?>

</textarea><br/>

<INPUT TYPE="SUBMIT" VALUE="Save">

</form> 

file 'saves/ranksave.php'
<?php

$f = fopen('c:/Users/Jack/Desktop/ventrilo/vetnrilo_srv.rank', 'w');

fwrite($f, $_POST['save']);

fclose($f);

header('Location: ../saved/ranksave.php');

?>

I am unsure if it not saving due to my PHP code error, or due to the fact that PHP can view(include) other files (.rank) but cannot edit them.

Hope someone can assist,
Jack.

#2
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
According to :
PHP: exec - Manual

Quote

For these persons who has problems running programs with graphical interfaces(windows) in Windows/Apache/PHP here is the solution:

Start > Run > "services.msc"

Search the Apache Service, right click and select Properties.

You will see two radio buttons, check the first if it isn't, and then check too the checkbox below.

Now restart Apache and oyu will see any kind of windows when executing a program.

Enjoy!

EDITED

See next post

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#3
Jack-ClansVoice

Jack-ClansVoice

    Newbie

  • Members
  • Pip
  • 6 posts

DEViANT said:

According to :
PHP: exec - Manual



EDITED

See next post


Lol, just when I'm about to do it!
Pending next post I guess.

#4
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
You can do the first part already. Still reading up on windows for the include files

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#5
Jack-ClansVoice

Jack-ClansVoice

    Newbie

  • Members
  • Pip
  • 6 posts
Also with the Apache thing, I think that only works for either bare Apache or Xampp. I'm using WAMP and the only thing remotely related to Apache in that services.msc is wampapache, which when right clicking on and going properties does not display any sort of radio buttons and/or checkboxes.

#6
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Your path to include files needs to be relevant to the directory that the script is running in. I would suggest moving/copying the file from your desktop to the folder that the script is running in and just include it dirrectly like so :


<?php include('filename.ext'); ?>


There is a way to include the file from your desktop, but you'd have to write a fairly built function for that. Also, you'd have to be running apache and IIS directly on your windows os and not a virtual interface.

What happens when you run the following command in your script?

<?php exec('start notepad.exe'); ?>


:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#7
Jack-ClansVoice

Jack-ClansVoice

    Newbie

  • Members
  • Pip
  • 6 posts
When i run that command in my script (which i have done previously) it does not load. The page just has the loading bars etc.

#8
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Hmmmm..... This might come back to it being wamp, but what happens when you use system() instead of exec() ?

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#9
Jack-ClansVoice

Jack-ClansVoice

    Newbie

  • Members
  • Pip
  • 6 posts
'Parse error: parse error in C:\wamp\www\index.php on line 3'

#10
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
This doesn't work because it is not suppose to. How safe would servers be if anyone could execute commands by simply loading them into a php script and executing it their browser? It is likely that when you look at your Task Manager (and Show processes from all users) a notepad.exe process is created and is being ran by the SYSTEM user, which probably doesn't have privileged to execute notepad, with good cause. If you want Apache to execute commands as a privileged user, you need to change the user that apache is being ran as, and I don't know how to do that because its dumb.

#11
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
That makes sense. Guess I learn something new everyday

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#12
Jack-ClansVoice

Jack-ClansVoice

    Newbie

  • Members
  • Pip
  • 6 posts
Indeed it does.