Solved

Convert $_GET $tring to $_POST $tring?

Posted on 2004-08-04
9
1,289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 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