PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old May 28th, 2002, 01:23 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
POST with PHP.. help

<?

I have a script here,

it posts data to a webserver (running ASP)

The URL is (when reccived at the other server): www.webserver.se/mottag.asp?dest=$dest&text=$text&from=$from
EXAKT like that, the vaules is not extracted from the variable..
I want the URL to be:
www.webserver.se/mottag.asp?dest=JENNY&text=testar&from=070404040404

The values should be generated from a database..

please advice.


function sendToHost($host,$method,$path,$data,$useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
$fp = fsockopen($host,80);
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.1n");
fputs($fp, "Host: $hostn");
fputs($fp, "Content-type: application/x-www-form-urlencodedn");
fputs($fp, "Content-length: " . strlen($data) . "n");
if ($useragent)
fputs($fp, "User-Agent: MSIEn");
fputs($fp, "Connection: closenn");
if ($method == 'POST')
fputs($fp, $data);

while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
return $buf;
}
$dest = "JENNY";
$text = "testar";
$from = "070404040404";
$string = "";
sendToHost('www.webserver.se','post','/mottag_sms.asp','dest=$dest&text=$text&from=$from');
?>

Reply With Quote
  #2  
Old May 28th, 2002, 02:27 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: POST with PHP.. help

sendToHost('www.webserver.se','post','/mottag_sms.asp','dest=$dest&text=$text&from=$from');

Put those in double quotes rather than single quotes:

sendToHost("www.webserver.se","post","/mottag_sms.asp","dest=$dest&text=$text&from=$from");

When you place things in single quotes, variable substitution does not happen. You need to use double quotes for what you want to do...


Reply With Quote
  #3  
Old June 2nd, 2002, 11:55 AM
dwd dwd is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 13 dwd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: POST with PHP.. help

Your script won't work if you tell it to use "GET", incidentally, since you're still passing in Content-Length.

Moreover, I wouldn't have the caller encode the data, I'd make $data be an array, of var => value, and then walk it, like this:

php Code:
Original - php Code
  1.  
  2. $data_send = '';
  3. reset( $data ); // Not needed, but I'm fussy.
  4. $first = true;
  5. while( list( $var, $value ) = each( $data ) ) {
  6.    if( $first ) {
  7.       $data_send .= '&';
  8.       $first = false;
  9.    }
  10.    $data_send .= urlencode( $var ) . '=' . urlencode( $value );
  11. }

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > POST with PHP.. help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway