Solved

Convert $_GET $tring to $_POST $tring?

Posted on 2004-08-04
9
1,280 Views
Last Modified: 2012-08-14
I have an java app that will send a url sting (domain.com/login.php?user=username&pass=password&etc...) to automaticly login to one site.  The other site only looks at $_Post[user] to get the login info.  I do not want to change the second website login method but i do want to login.  

Q: Is there a way I could make a script to take my url $tring [$_GET] and turn it into a post string [$_POST]?

0
Comment
Question by:greyhair
9 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11721291
Use $_REQUEST['name']

Regards,
${Zyloch}  
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 84 total points
ID: 11721385
you really should not send passwords in the url query string, can you not set up your java app to send the data via post
0
 
LVL 25

Assisted Solution

by:Marcus Bointon
Marcus Bointon earned 83 total points
ID: 11721509
Using $_REQUEST would require him to change the code on the receiving site, which he said he can't do.

You could write a proxy that converts an HTTP GET to a POST, accepting the GET request and generating a new POST request using CURL, then passing the results back to the original requester. Roughly like this:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.postdomain.com/login.php'); //Set to your target URL
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_SERVER['QUERY_STRING']);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec($ch);
curl_close($ch);
?>

The curl_exec will just dump whatever comes back from this POST request to the original GET requester. You might need to a be a little more careful with what you pass into CURLOPT_POSTFIELDS, but the principle should hold together. You may also need/want to pass through various other info from the original requester (in the same way as I have with user agent). Also bear in mind that this route will make it look like your server rather than the requester is the real requester, which may mean that the log works, but only for your server's IP address, depending on how they have their login script set up.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 18

Assisted Solution

by:arantius
arantius earned 83 total points
ID: 11743466
Point your java app to this PHP page, and this form's action to the real app:


<html>
<head>
<title>whatever</title>
</head>
<body>

<form method="post" action="http://......../">
<?
foreach ($_GET as $key => $value) {
  printf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />", $key, $value);
}
?>
<button type="submit">Continue login...</button>
</form>
</body>
</html>
0
 

Expert Comment

by:savtrad
ID: 23359211
You can use Java Script to submit a form with Post values activated by a hyper link. This will give you a hyper link appearance which will submit form vaues using the post menthod.
Place this java script between your head tags. Use hidden input form fields for additioal post values sent by the java script activated submit action.

<html>
<head>
<title>Title</title>
<script language="JavaScript" type="text/javascript">
<!--
function submitlink ( postvalue )
{
  document.linkform.area_session.value = postvalue ;
  document.linkform.submit() ;
}
-->
</script>
 
</head>
<body>
<form name="linkform" action="/index.php" method="POST" >
    <input type="hidden" name="area_change" value="Change" />
    <input type="hidden" name="area_session" />
    <a href="javascript:submitlink('Members_Area')">Members Area</a><br />
    <a href="javascript:submitlink('Free_Area')">Free Area</a><br />
                        </form>
</body>
</html>

Open in new window

0
 
LVL 36

Expert Comment

by:Zyloch
ID: 23359319
Wow, this is so old. Back in the times when I was still young and naive =)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Creating Functions in phpMyAdmin 8 26
How to obtain the string from a PHP StdObject ? 6 33
Ahax pagination 9 33
AJAX Wordpress Not Reading Variable 2 28
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question