Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-19-2006, 02:35 PM   #1
Registered: Nov 2005
Location: Suffolk, UK
Distribution: kubuntu 9.04
Posts: 188

Rep: Reputation: 30
Adding users with PHP (pass php variables to Expect script)

Hi there, I could't find an answer already here so I've made a post, forgive me if the answer is here but I couldnt find it.

Ok so here goes, I have a php page that takes a username in( from textbox), i want to send that username thru to an Expect script

The expect script will log in as root, add the user, do whatever else i decide, then switch out of root.

heres what I've come up with so far...

The first page, with the form that takes in the username


<h1>The worst User management ever...</h1><p>
<form name="userdata" action="process.php" method="post">
Username:<input name="username" type="text"><br>
Password:<input name="password" type="text"><br>

<input type="submit">

The username gets passed into this php file, and echoed back on the screen for confirmation, this part works fine

$username = $_POST['username'];
$password = $_POST['password'];
//$username = "jack";
//$password = "1234";


//Run some linux script to actually ADD the user, only passing 1 var till //i can work it out

exec("/opt/lampp/htdocs/wse/adding.exp". $username);

echo "Your Username is ". $username .".<br>";
echo "Your Password ir ". $password .".<br>";

<a href="index.html">Go back and try again</a>

the username should be sent here, then added to the linux box, but this doesn't work
#! /usr/bin/expect -f


set force_conservative 0

spawn su
match_max 100000
send -- "password\r"
send -- "useradd username\r"
send -- "exit\r"
expect eof
I think that the initial data is being passed to the second php file becuase it is echoed back on screen, but as for being sent to the exp script I have no idea

Can someone please help me solve this problem, I'm having little luck finding tutorials/solutions on the internet

Thank you for your time

Old 10-20-2006, 11:44 AM   #2
Registered: Jul 2004
Location: Gloucestershire, UK
Distribution: Ubuntu, Debian & Gentoo
Posts: 74

Rep: Reputation: 16
At a glance, you would need a space between adding.exp and $username

So change

PHP Code:

PHP Code:
exec("/opt/lampp/htdocs/wse/adding.exp "$username); 
I don't know anything about expect but the PHP looks alright to me. You can get the browser to display the output from your exec command like this:

PHP Code:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a row to another PHP script bahadur Programming 5 12-24-2011 02:07 AM
pass variables through hyperlink in php ALInux Programming 2 12-23-2005 02:27 PM
Adding javascript variables to a PHP query Elijah Programming 7 11-07-2004 08:28 PM
Pass multiple URL variables PHP agallant Programming 3 10-21-2004 08:29 PM
How to pass arguments from $prompt for php script ukjairaj Linux - Software 4 06-25-2004 12:14 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration