Visit Jeremy's Blog.
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 04-13-2011, 10:55 AM   #1
LQ Newbie
Registered: May 2006
Location: Manchester, NH
Distribution: CentOS5.5
Posts: 13

Rep: Reputation: 0
HTML to PHP to EXPECT formatting issue

I'm new to PHP, so I may be missing something obvious or it could be something with the HTML. I wrote an expect script that tests user authentication against a RADIUS server. The username is an email address, including an @ sign. I recently wrote an HTML/PHP front end to allow others to input username/password into a form and then see the results when they hit submit.

Expect code that takes two args username, and password
expect "#"

send    "test aaa group radius [lindex $argv 0] [lindex $argv 1] new-code\r"

expect  "#"
This works fine as far as I can tell, the two input boxes pass the input to the php script
<title>Authentication Test</title>
<form method= "post" action= "authentication.php">
<font size = "5" color = "blue"><b><u>USER AUTHENTICATION TOOL</u></b></font><br /><br />
<input type="text" size="30" maxlength="50" name="unstring"/><br />
<input type="text" size="30" maxlength="50" name="pwstring"/><br /><br />

<input type="submit" value="submit" name="submit"/><br />
</form><br />

This is the php
<?$uname = $_POST['unstring']?>

<?$passw = $_POST['pwstring']?>

<?$output = shell_exec("expect authentication1.exp {$uname} {$passw}")?>

<?echo "<pre>$output</pre>"?>
Every works as it's supposed to, except for the output of the script. When it displays on the webpage, it's segmented weirdly with  all throughout. What I've found is when I remove the @ sign in the username input, it fixes it.

Is there any part of HTML or PHP that treats the @ as a special character? 1 more thing is that I have another HTML/PHP/EXP script that works fine with the @.

Old 04-16-2011, 07:53 AM   #2
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
I'll bet that you'll need to use addslashes() or stripslashes()
which will handle the escaping of special characters.

I suspect the problem is in the assignment of $passw. Try this
and see if it works.

<?$passw = addslashes($_POST['pwstring'])?>
Old 04-18-2011, 04:46 PM   #3
LQ Newbie
Registered: May 2006
Location: Manchester, NH
Distribution: CentOS5.5
Posts: 13

Original Poster
Rep: Reputation: 0
I tried wrapping the addslashes and stripslashes tags around the POST variables, but it did not seem to fix the problem. I could have been applying them wrong.

I figured out another way display the results I was looking for, so to solve the strange coding problem I just had the expect script echo something if a regexp were true, instead of the expect script just echo'ing the direct router output.

send    "test aaa group radius [lindex $argv 0] [lindex $argv 1] new-code\r"

                expect  "#"

                set output $expect_out(buffer)

                set hostindex [lindex $output end]

                set hostname [string trim $hostindex "#"]

                if { [regexp -all "User rejected" $output] == "1" } {

                        puts "$hostname = User Rejected\n"

                } elseif { [regexp -all "User successfully authenticated" $output]  == "1" } {

                        puts "$hostname = User successfully authenticated\n"

                } else {

                        puts "$hostname = Unknown Condition\n"


expect, html, php, tcl

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
shell script help with HTML formatting (??) cbtshare Programming 9 01-12-2010 11:09 AM
HTML Table Formatting Inbhir Pheofharain Programming 17 07-20-2009 04:02 PM
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 11:44 AM
html formatting thunderbird sharky Linux - Software 4 01-17-2006 03:33 PM
Howto turn off html formatting in OpenOffice jlinkels Linux - Software 1 12-22-2005 02:56 PM

All times are GMT -5. The time now is 02:23 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