homepage Welcome to WebmasterWorld Guest from 54.198.94.76
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to capture login username and send to php script
capture htppasswd username for php script
syd1975




msg:1255935
 1:30 pm on May 7, 2003 (gmt 0)

I have an html form in an .htaccess/.htpasswd protected directory. When the user logs in, I want to capture his/her username on my html form and then send it as a hidden value to the php script, which is on a different server (not password protected). Seems simple to me, but I can't get it to work.

In my html form, I have the following lines:

<pre>
<form action="myform.php" method="post">
<input type=hidden name="id" value="SERVER['REMOTE_USER']">
<input type=submit value="submit">
</form>
</pre>

But, when I send the above to my php script:

$id=$_POST['id'];
echo "$id";

it just outputs server remote user, but not the username. Any suggestions? Thanks.

 

BGumble




msg:1255936
 1:45 pm on May 7, 2003 (gmt 0)

Change your form line to:

<input type=hidden name="id" value="<?=SERVER['REMOTE_USER']?>">

Which will interrupt the HTML and tell it to output that PHP variable.

syd1975




msg:1255937
 2:13 pm on May 7, 2003 (gmt 0)

Thanks. Seemed to make sense, but when I tried it, my echo "$id"; was just blank this time.

BGumble




msg:1255938
 2:30 pm on May 7, 2003 (gmt 0)

Oops I forget the $$$$_ :)

<input type=hidden name="id" value="<?=$_SERVER['REMOTE_USER']?>">

toadhall




msg:1255939
 2:31 pm on May 7, 2003 (gmt 0)

Shouldn't that be $_SERVER['REMOTE_USER']?

T

toadhall




msg:1255940
 2:32 pm on May 7, 2003 (gmt 0)

I guess it should ;o)

syd1975




msg:1255941
 2:44 pm on May 7, 2003 (gmt 0)

Still didn't work. The field on browser was still blank, and when I looked at the source code for my php file, it said:

[PHP]Your user id is <?=$_SERVER[\'REMOTE_USER\']?>.[/PHP]

Maybe it won't work because the php file's on a different server that doesn't require authentication?

BGumble




msg:1255942
 2:50 pm on May 7, 2003 (gmt 0)

I've never used that specific variable, so hopefully someone else can help!

syd1975




msg:1255943
 2:56 pm on May 7, 2003 (gmt 0)

Okay, thanks for trying. I didn't think it would be that difficult to do...grabbing a username. But, again, it could have to do with the fact that the files are on two different servers.

BGumble




msg:1255944
 4:57 pm on May 7, 2003 (gmt 0)

The easiest way to program with these variables is to look at a phpinfo script to see what variables are being passed from your browser. If you don't know what that is, it's a simple one line script with <? phpinfo();?>

syd1975




msg:1255945
 5:33 pm on May 7, 2003 (gmt 0)

Thanks. I do have a phpinfo file. The only problem is that is run on the server that is not password protected, so it wouldn't show any values for username and password.

I can get the username via a cgi script, so, I guess the solution, for now, would be to get it that way and then pass it on the php script. I was just trying to get away from having to use the cgi. Thanks for your help.

toadhall




msg:1255946
 7:04 pm on May 7, 2003 (gmt 0)

...capture his/her username on my html form and then send it as a hidden value to the php script, which is on a different server...

<note to self>Read a little more carefully next time</note to self>

The php code <?=$_SERVER['REMOTE_USER']?> is in an html file running on a server that doesn't parse php, so the php code isn't going to do anything. The html code is doing what it ought to: sending the value of 'id', literally <?=$_SERVER['REMOTE_USER']?>, to the second server.

> I can get the username via a cgi script...

:)

T

syd1975




msg:1255947
 7:37 pm on May 7, 2003 (gmt 0)

Thanks, toadhall. And, as it turns out, I couldn't even get it to work with CGI. I searched bulletin boards all over and saw others who were asking the same question (with no responses), so a lot of others were(are) having the same problem that I am.

Thought it might have to do with <Limit Get> in my .htaccess file, but when I changed to <Limit Get Post>, I still wasn't able to capture the remote_user name.

Luckily, the number of people completing this particular survey is small (31) so I'll probably wind up just creating a table and reentering all access codes there.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved