Jump to content

problem in running simple touch command with php


tanveer

Recommended Posts

 

Hi all,

 

I am trying to create a user in linux with php but its not getting created. I also added apache user in sudoers file in linux.

 

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="newuser.php">
<p>Login:
<input name="login" type="text" id="login">
</p>
<p>Nombre Completo:
<input name="nombre" type="text" id="nombre">
</p>
<p>Password:
<input name="pwd" type="password" id="pwd">
</p>
<p>
<input type="submit" name="Submit" value="Crear">
</p>
</form>
</body>
</html>

<?php
if (isset($_POST['login'])) {
$login=$_POST['login'];
$nombre=$_POST['nombre'];
$passwd_crypt=crypt($_POST['pwd']);

#$res='/bin/bash /var/www/cgi-bin/newuser $login "$nombre" $passwd_crypt';
$res='/var/www/cgi-bin/newuser';
echo $res;
exec ("$res");
echo "<br><br>User Created";
}
?>

Then I changed the code to make sure whether its really working or not by this below just to create a file but still it doesn't work.

/var/www/cgi-bin/newuser
sudo touch /tmp/abc

Any help.

Those dont look like "back ticks" in the $res. The shell wont execute it if its not back ticked. You should not even need the exec, in PHP it will use the ticks and do it itself. The back tick is right below the "tilde", upper left of the keyboard.

 

I dont know what your shell script looks like but you have to sudo everything. Is it your box? If not do you have root perms or been made a super-user. If not you wont be able to do anything. Is "safe mode" turned on. If so you have to set the folder you have executables in with safe_mode_exec_dir.

 

If this confuses you you should spend some time with:

Linux "Little Black Book"

Linux in a nutshell

 

 

HTH

Teamatomic

No the back tick doesn't work.

 

This is my script: just 2 lines to create a file in /tmp for testing

#!/bin/bash

sudo touch /tmp/abc

 

in /etc/sudoers I also have an entry

apache ALL=(ALL)  ALL

 

<?php
$res=`/var/www/cgi-bin/newuser.sh`;
echo "<br><br>File Created";
?>

 

And safe_mode if off in php.ini

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.