Just nu i M3-nätverket
Jump to content

HTTP POST i php


Marcus Svensson

Recommended Posts

Marcus Svensson

Hej

 

Jag vet att man kan göra HTTP POSTS i perl och ASP men vet någon hur man gör det i PHP, har funderat på det länge, det skulle vara väldigt bra att posta några variabler till en server utan redirect och sedan få den att vänta på ett confirmation mess.

 

 

 

</\> MVH

<||> Marcus Svensson

<||> http://war.gamelegacy.org

<||> webmaster@svenneman.com

<\/>

Link to comment
Share on other sites

Marcus Svensson

2 exempel från paypal.com

 

<%@LANGUAGE="VBScript"%>

<%

Dim str, OrderID, Txn_id, Payment_status

Dim objHttp

 

str = Request.Form

OrderID = Request.Form("item_number")

Txn_id = Request.Form("txn_id")

Payment_status = Request.Form("payment_status")

 

' post back to PayPal system to validate

str = str & "&cmd=_notify-validate"

set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false

objHttp.Send str

 

' Check notification validation

if (objHttp.status <> 200 ) then

' HTTP error handling

elseif (objHttp.responseText = "VERIFIED") then

' process payment

elseif (objHttp.responseText = "INVALID") then

' possible fraud

else

' error

end if

set objHttp = nothing

%>

 

 

 

 

 

Link to comment
Share on other sites

Marcus Svensson

#!/usr/local/bin/perl

 

# read the post from PayPal system and add 'cmd'

read (STDIN, $query, $ENV{'CONTENT_LENGTH'});

$query .= '&cmd=_notify-validate';

 

# post back to PayPal system to validate

use LWP::UserAgent;

$ua = new LWP::UserAgent;

$req = new HTTP::Request 'POST','https://www.paypal.com/cgi-bin/webscr';

$req->content_type('application/x-www-form-urlencoded');

$req->content($query);

$res = $ua->request($req);

 

# split posted variables into pairs

@pairs = split(/&/, $query);

$count = 0;

foreach $pair (@pairs) {

($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$variable{$name} = $value;

$count++;

}

 

# assign posted variables to local variables

$receiver_email = $variable{'receiver_email'};

$item_name = $variable{'item_name'};

$item_number = $variable{'item_number'};

$custom = $variable{'custom'};

$payment_status = $variable{'payment_status'};

$payment_date = $variable{'payment_date'};

$payment_gross = $variable{'payment_gross'};

$payment_fee = $variable{'payment_fee'};

$txn_id = $variable{'txn_id'};

$first_name = $variable{'first_name'};

$last_name = $variable{'last_name'};

$address_street = $variable{'address_street'};

$address_city = $variable{'address_city'};

$address_state = $variable{'address_state'};

$address_zip = $variable{'address_zip'};

$address_country = $variable{'address_country'};

$payer_email = $variable{'payer_email'};

if ($res->content eq 'VERIFIED') {

# check transaction for uniqueness

# process payment

}

elsif ($res->content eq 'INVALID') {

# possible fraud

}

else {

# error

}

 

 

 

</\> MVH

<||> Marcus Svensson

<||> http://war.gamerpost.com

<||> webmaster@svenneman.com

<\/>

 

 

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...