Welcome to WebmasterWorld Guest from 54.159.250.110

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to capture login username and send to php script

capture htppasswd username for php script

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

10+ Year Member



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.

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

10+ Year Member



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.

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

10+ Year Member



Thanks. Seemed to make sense, but when I tried it, my echo "$id"; was just blank this time.
2:30 pm on May 7, 2003 (gmt 0)

10+ Year Member



Oops I forget the $$$$_ :)

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

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

10+ Year Member



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

T

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

10+ Year Member



I guess it should ;o)
2:44 pm on May 7, 2003 (gmt 0)

10+ Year Member



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?

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

10+ Year Member



I've never used that specific variable, so hopefully someone else can help!
2:56 pm on May 7, 2003 (gmt 0)

10+ Year Member



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.
4:57 pm on May 7, 2003 (gmt 0)

10+ Year Member



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();?>
5:33 pm on May 7, 2003 (gmt 0)

10+ Year Member



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.

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

10+ Year Member



...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

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

10+ Year Member



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.