PHP code to post data?
Moderator: General Moderators
PHP code to post data?
I've got a php file that uses the GET command to receive some data, but then I want it to post it through another form as if someone had used the post command. So this is what I have (draft, so no real code yet):
GET name $name
post http://mysite/myfile.php name=$name
What code to I nead to post my data (name = $name) to that other file?
GET name $name
post http://mysite/myfile.php name=$name
What code to I nead to post my data (name = $name) to that other file?
-
brendandonhue
- Forum Commoner
- Posts: 71
- Joined: Mon Sep 25, 2006 3:21 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Everah | Even for small amounts of code, please use the appropriate code tags.
I've decided to go with the fsockopen method. THis is my code so far:
ATM I'm getting this error: Parse error: syntax error, unexpected T_STRING in /home/gelid/domains/gelidscripts.frih.net/public_html/supertool/verify.php on line 4
Any ideas?
Also, this is for a friend who wants an app to be able to log in to runescape. It will send the user and pass through GET to my page, this one, which will then post it through, what this form would do:
Is what I'm doing the only way you can see to get it to work?
Everah | Even for small amounts of code, please use the appropriate code tags.
I've decided to go with the fsockopen method. THis is my code so far:
Code: Select all
<?php
$username = $GET['username'];
$password = $_GET['password'];
$handle = fsockopen('https://password_history.runescape.com/lang/en/aff/runescape/login.ws','a')
fwrite($handle,$password)
fclose($handle)
?>Any ideas?
Also, this is for a friend who wants an app to be able to log in to runescape. It will send the user and pass through GET to my page, this one, which will then post it through, what this form would do:
Code: Select all
<form action="https://password_history.runescape.com/lang/en/aff/runescape/login.ws" method="post" autocomplete="off">
RuneScape username:
<input size="20" type="text" name="username" maxlength="12">
RuneScape password:
<input size="20" type="password" name="password" maxlength="20">
<input type="submit" value="Verify Details">
<input type="hidden" name="dest" value="passchange.html">
</form>Everah | Even for small amounts of code, please use the appropriate code tags.
Great. Its all tweaked a bit, now I'm getting this:
Warning: fwrite(): supplied argument is not a valid stream resource in /home/gelid/domains/gelidscripts.frih.net/public_html/supertool/verify.php on line 5
This is my handle:
$handle = fsockopen('https://password_history.runescape.com/lang/en/aff/runescape/login.ws');
Warning: fwrite(): supplied argument is not a valid stream resource in /home/gelid/domains/gelidscripts.frih.net/public_html/supertool/verify.php on line 5
This is my handle:
$handle = fsockopen('https://password_history.runescape.com/lang/en/aff/runescape/login.ws');
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
That means that you do not have permission to access that file. The call to fsockopen() is failing.
-
brendandonhue
- Forum Commoner
- Posts: 71
- Joined: Mon Sep 25, 2006 3:21 pm
PHP needs to have OpenSSL support enabled to connect to secured sites with fsockopen(). Here's some code to get you started
Code: Select all
<?php
function RuneScape($data)
{
foreach($data as $key=>$value)
{
$post .= urlencode($key) . '=' . urlencode($value) . '&';
}
$post = substr($post, 0, -1);
$fp = fsockopen('ssl://password_history.runescape.com', 443);
if(!$fp)
{
return false;
}
$out = 'POST /lang/en/aff/runescape/login.ws' . " HTTP/1.0\r\n";
$out.="Host: password_history.runescape.com\r\n";
$out.="Content-Length: ".strlen($post)."\r\n";
$out.="Connection: close\r\n\r\n" . $post;
fwrite($fp, $out);
while (!feof($fp))
{
$response .= @fgets($fp);
}
fclose($fp);
if(strpos($response, '/passchange.html'))
{
return true;
}
return false;
}
$data['username'] = 'username';
$data['password'] = 'password';
$data['submit'] = 'Verify Details';
$data['dest'] = 'passchange.html';
if(RuneScape($data))
{
echo 'Login successful.';
}
else
{
echo 'Login failed.';
}
?>