Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having problem with php post with curl
08-09-2008, 09:32 PM (This post was last modified: 08-09-2008 09:34 PM by daniel.)
Post: #1
Having problem with php post with curl
I want to do a php submit from server A to a form on server B but I dont want the browser to end up showing a url on server A it should be now on a page on server B.

Was trying to use curl but it did not seem to work any help you can give me on this would be great.
Sorry forgot to add code:

PHP Code:
<?php 

  $header
[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  
$header[] = "Cache-Control: max-age=0"
  
$header[] = "Connection: keep-alive"
  
$header[] = "Keep-Alive: 300"
  
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
  
$header[] = "Accept-Language: en-us,en;q=0.5"

$search 'hello world'
$url 'Http://www.google.com'
$curl curl_init(); // Initialize the cURL handler 
curl_setopt($curlCURLOPT_HTTPHEADER$header); 
curl_setopt($curlCURLOPT_USERAGENT'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9) Gecko/2008052906 Firefox/3.0'); 
curl_setopt($curlCURLOPT_ENCODING'gzip,deflate'); 
curl_setopt($curlCURLOPT_FOLLOWLOCATION1); // Follow any redirects, just in case 
curl_setopt($curlCURLOPT_AUTOREFERERtrue); 
curl_setopt($curlCURLOPT_URL$url); // Set the URL 
curl_setopt($curlCURLOPT_POST1); // set POST method (to send our search) 
curl_setopt($curlCURLOPT_POSTFIELDS'q= .$search. &hl=en&btnG=Search&meta='); // What we will be searching for 
curl_exec($curl); // Display page 
curl_close($curl); // Close cURL handler 

?>
Thanx
Find all posts by this user
Quote this message in a reply
08-09-2008, 09:35 PM
Post: #2
RE: Having problem with php post with curl
Curl runs on the server side, you can't use it to force the browser to redirects. Use header() instead. Here's a snippet to query google:


PHP Code:
<?php 
$search 
'hello world!'
header('Location: http://www.google.com/search?q=' $search '&hl=en&btnG=Search&meta='); 
?>
Cheers!


Warm Regards,
Website Design India
Submit Free Links
Website Design Faridabad
Visit this user's website Find all posts by this user
Quote this message in a reply
08-09-2008, 09:36 PM
Post: #3
RE: Having problem with php post with curl
Thank I guess google was just an example. if I can not use Curl does that mean I have to use sockets ?

I want to redirect the browser to the remote servers output I dont want to show the user the output from the remote server on my website (if that makes sense)
Find all posts by this user
Quote this message in a reply
08-09-2008, 09:37 PM (This post was last modified: 08-09-2008 09:37 PM by ved.)
Post: #4
RE: Having problem with php post with curl
Ok I understand. But I don't think this could be done on the server side. Maybe you could use a simple javascript tricks.

I assume this scenario:
1. you have a page http://www.mydomain.com/myfile.php
2. if a client request the file, automatically post some data to http://www.somedomain.com/somefile.php
3. redirect the client's browser to the remove server, which displays the output from previous action.

Here's the contents of myfile.php

PHP Code:
<form name="form_1" action="http://www.somedomain.com/somefile.php" method="post">
<
input type="hidden" name="field_1" value="value_1">
<
input type="hidden" name="field_2" value="value_2">
<
input type="hidden" name="field_3" value="value_3">
</
form>

<
script type="text/javascript">
document.form_1.submit();
</script> 
Cheers!
You might want to use Apache RewriteRules on the first server, then use Deny/Allow directives to prevent people from accessing the remote server directly.

Also consider file_get_contents ('http://otherserver.com/file.php'), etc - possibly even include 'http://otherserver.com/file.php';


Warm Regards,
Website Design India
Submit Free Links
Website Design Faridabad
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:

Contact UsDeveloper SolutionReturn to TopReturn to ContentLite (Archive) ModeRSS Syndication