POSTing Data Without a Form?
I have a site that uses a form with the POST method to allow users to login.
I am converting over to LDAP and no longer need this form, however I would still like to 'fake' the action of the form using the username authenticated by LDAP.
Is there a way for PHP to POST a bunch of data to the server without using a form? I really want the UI to be as transparent as possible.
My current path is to continue to build the form, just make all the fields hidden and use javascript to 'submit' the form. I've only been partially successful as it seems I still need the 'submit' button in the form and that shows up in the UI even if the user doesn't need to actually push it. <- not completely transparent
If I could just fill in the vars and post it directly from PHP (or even javascript) it would be much better.
Anyone have any ideas?
[916 byte] By [
mphare] at [2007-11-19 10:52:55]

# 1 Re: POSTing Data Without a Form?
If I understand you correctly you basically want PHP to act as a proxy to the old script (at least in terms of login), if so I think this is what you are looking for http://www.alt-php-faq.org/local/55/#id55
Although it doesn't go into very much detail.
If you can't get it to work post here again, I'll try to help as much as I can.
khp at 2007-11-10 3:58:19 >

# 2 Re: POSTing Data Without a Form?
Here's my idea on how you can make the submit button transparent: Instead of using Input type "submit", you can use type "image". This tells the browser you are using a graphical button whose sole action is to submit the form. You just need to make a transparent .gif file (you can try a 1 x 1 pixel image). Then just put the following code in place of the original submit button:
<input type="image" name="submit" src="submit.gif" height="1" width="1">
// Just my two cents. :)
# 3 Re: POSTing Data Without a Form?
Yes, I have a couple of phpNuke sites here. Rather than require the software group, and everyone else that might want to access one of the sites, to go through a registeration process, I'm going to leverage our LDAP server and challange the users at the HTTPD server layer.
Using the information from a successful LDAP authentication, I have altered phpNuke to create entries in the user table as new users access the site. This way I can still maintain user profiles, but I can also modify as little code as posible in phpNuke. So far I've only had to change four php file, two of which were essentially single line change.
I have to fake User Login evertime a user accesses the site and New User Activation everytime a new user accesses the site.
It works fine, but the process is a little jerky as the forms fumble around.
cURL looks good, but I don't to rely on a third party library or extension. Manually creating an HTTP POST header and body was one of my original thoughts, I was just hoping there was a php construct that I was not aware of (something like cURL).
I like the idea of the 1x1 transparent GIF image instead of a button. That would at least get rid of a useless button on the screen.
Thanks for all the help!
mphare at 2007-11-10 4:00:23 >

# 4 Re: POSTing Data Without a Form?
You can use Javascript to submit the form. Make sure you give it a name and put this at the bottom of the page. No need for a submit button either :)
<script type="text/javascript">
<!--
doecuments.formname.submit();
//-->
</script>
# 5 Re: POSTing Data Without a Form?
You can use Javascript to submit the form. Make sure you give it a name and put this at the bottom of the page. No need for a submit button either :)
That's neat. I might be able to use that one day. :thumb:
# 6 Re: POSTing Data Without a Form?
You can use Javascript to submit the form. Make sure you give it a name and put this at the bottom of the page. No need for a submit button either :)
<script type="text/javascript">
<!--
doecuments.formname.submit();
//-->
</script>
Well, that's what I'm presently doing.. except I found if I don't have the Submit button nothing happens when the script executes.
Maybe I'll remove the submit button and try again.
Thanks!
mphare at 2007-11-10 4:03:34 >

# 7 Re: POSTing Data Without a Form?
Must have had a bug in the code. I just removed the Submit button and the script works like a champ.
Thanks again.
mphare at 2007-11-10 4:04:27 >

# 8 Re: POSTing Data Without a Form?
I have a site that uses a form with the POST method to allow users to login.
I am converting over to LDAP and no longer need this form, however I would still like to 'fake' the action of the form using the username authenticated by LDAP.
Is there a way for PHP to POST a bunch of data to the server without using a form? I really want the UI to be as transparent as possible.
My current path is to continue to build the form, just make all the fields hidden and use javascript to 'submit' the form. I've only been partially successful as it seems I still need the 'submit' button in the form and that shows up in the UI even if the user doesn't need to actually push it. <- not completely transparent
If I could just fill in the vars and post it directly from PHP (or even javascript) it would be much better.
Anyone have any ideas?
Hi!
what type of data you want send to server without FORM?
you can Passing Data with URLs if data are small .
for big data you can use DataBase .
# 9 Re: POSTing Data Without a Form?
Hi , you can use socket ( http://www.php.net/socket) or curl ( http://www.php.net/curl) libraries.
Example usage of posting data with curl ( http://curl.haxx.se/libcurl/php/examples/?ex=simplepost.php)
Yns at 2007-11-10 4:06:33 >

# 10 Re: POSTing Data Without a Form?
Regarding this one, I am using 'wget' shell command with the correct parameters with the backtick operators (``) of PHP. Read about the PHP backtick operators and the 'wget' program. This works well!
# 11 Re: POSTing Data Without a Form?
well, you can open a connection to the other script yourself and send whatever the browser would send on the submission of that form.
lets see how a POST request looks like (post request with firefox 1.0.6):
POST /path/to/your/script.html HTTP/1.1
Host: www.yourserver.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: NotNecessaryUnlessYourScriptChecksThis
Content-Type: application/x-www-form-urlencoded
Content-Length: 40
Your=Variables&Like=In&An=Get&Request=0
So... Some of the Headerfields above are unnecessary, unless the target script does depend on them.
So.. the importing stuff are the POST data here... as you can see there are two header fields regarding the content of this request.
<sidenote>
What you should know (i think you know it, just for completeness :) ): the difference between a post and a get request is, that post delivers its data in the body of the request, say in the content part; get delivers its data right in the first header field (appending the values to the requested uri)... so it can be, that GET requests are limited in the amount of payload they can transmit.....
</sidenote>
the two candidates are Content-Type and Content-Length. Content-Type is
rather static, it only differs if you have a form which submits files...
The dynamic one of the both is Content-Length, this should contain the length in bytes (say charachters) of the payload.
The payload itself, the POST variables, has the same syntax as with an GET request.
So you can build the varibles string get the string length and you hav the value for Content-Length.
Know you open a connection with fopen to the target server and write all header fields and payload to the stream... wait for the answer and close the connection.
By the way: you don't need all of the aboves header fields just a few are necessary... (hm.. i said this twice already, didn't i... :sick: )
$sRequest = "POST /path/to/your/script.html HTTP/1.1\r\n";
$sRequest .= "Host: www.yourserver.com\r\n";
$sRequest .= "Keep-Alive: 300\r\nConnection: keep-alive\r\n";
$sRequest .= "Content-Type: application/x-www-form-urlencoded\r\n";
$sRequest .= "Content-Length: ";
$sPayload = "Username=".$sUserName."&Password=".$sPassword";
$sRequest .= strlen($sPayload)."\r\n\r\n";
$sRequest .= $sPayload;
$handle = fopen("http://www.yourserver.com/", "rw");
fwrite($handle, $sRequest);
$sReply = '';
while (!feof($handle)) {
$sReply .= fread($handle, 8192);
}
fclose($handle);
didn't test the code.. but besides some syntax erros (maybe :rolleyes: ) it should work.
have fun!
bigBA at 2007-11-10 4:08:33 >

# 12 Re: POSTing Data Without a Form?
oh.. khp posted this way already... sorry for that :o
bigBA at 2007-11-10 4:09:30 >
