Using the $_POST global

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Using the $_POST global

Post by Dugi » Mon Sep 17, 2012 7:00 pm

I have this class I have found online and it uses $_POST one time and MPV gives me a fail for that. But, unfortunately, I can't remove it because request_var() wont serve my needs this time.

This is the case:

Code: Select all

if (!empty($_POST)) 
{
     $this->post_data = $_POST;
     $encoded_data .= '&' . file_get_contents('php://input');
} 
Is there a way to workaround this in a phpBB way?
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51824
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Using the $_POST global

Post by Brf » Mon Sep 17, 2012 7:04 pm

I am not sure $_POST should ever be empty.
I am guessing you should be able to check request_var() on the submit button of your form or something.

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Using the $_POST global

Post by Dugi » Mon Sep 17, 2012 7:09 pm

There is no submit button on this one. This page should be requested by Paypal only, not users. Actually, it's just a blank white page.
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: Using the $_POST global

Post by Erik Frèrejean » Tue Sep 18, 2012 4:59 am

What code are you attempting to use?
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Using the $_POST global

Post by Dugi » Tue Sep 18, 2012 5:22 am

Erik Frèrejean wrote:What code are you attempting to use?
I have this class that communicates with Paypal, and the method look like this:

Code: Select all

    public function processIpn($post_data = null) 
    {
        $encoded_data = 'cmd=_notify-validate';
        
        if ($post_data === null) 
        { 
            // use raw POST data 
            if (!empty($_POST)) 
            {
                $this->post_data = $_POST; // these lines here
                $encoded_data .= '&' . file_get_contents('php://input');
            } 
            else 
            {
                throw new Exception("No POST data found.");
            }
        } 
        else 
        { 
            // use provided data array
            $this->post_data = $post_data;
            
            foreach ($this->post_data as $key => $value) 
            {
                $encoded_data .= "&$key=" . urlencode($value);
            }
        }

        if ($this->use_curl) 
        {
            $this->curlPost($encoded_data); 
        }
        else
        {
            $this->fsockPost($encoded_data);
        }
        
        if (strpos($this->response_status, '200') === false) 
        {
            throw new Exception("Invalid response status: " . $this->response_status);
        }
        
        if (strpos($this->response, "VERIFIED") !== false) 
        {
            return true;
        } 
        elseif (strpos($this->response, "INVALID") !== false) 
        {
            return false;
        } 
        else 
        {
            throw new Exception("Unexpected response from PayPal.");
        }
    }
Ignore the hard-coded language.

And in the main Listener file, I call this method...

Code: Select all

$listener = new ipn_listener();

try 
{
    $listener->requirePostMethod();
    $verified = $listener->processIpn();
    global $db;
} 
catch (Exception $e) 
{
    add_log('critical', (string) $e->getMessage());
    exit;
}

if ($verified) 
{
     // everything is valid
}
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: Using the $_POST global

Post by Erik Frèrejean » Tue Sep 18, 2012 10:14 am

I think you are using this library?

I think that this would be an instance where you can ignore the MPV result as accessing the $_POST array would be allowed. However don't take my word on that and make sure that you get confirmation from a MOD team member.
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Using the $_POST global

Post by Dugi » Tue Sep 18, 2012 11:05 am

Erik Frèrejean wrote:I think you are using this library?

I think that this would be an instance where you can ignore the MPV result as accessing the $_POST array would be allowed. However don't take my word on that and make sure that you get confirmation from a MOD team member.
Yes exactly, that's the class I am using.

I too think that my case is a special one and should have the MPV result ignored this time, but as you said, waiting for a MOD Team member to confirm this would be more appropriate.
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Using the $_POST global

Post by Dugi » Thu Sep 20, 2012 5:15 am

Bump.
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
prototech
Former Team Member
Posts: 5406
Joined: Mon Mar 19, 2007 2:04 pm
Location: Southern California

Re: Using the $_POST global

Post by prototech » Thu Sep 20, 2012 11:09 pm

Third party libraries do not have to follow the phpBB Coding Guidelines, so yes, that's fine.
Need help with MOD/style installations or other phpBB problems? Contact me for a quote.

Locked

Return to “[3.0.x] MOD Writers Discussion”