Link to home
Start Free TrialLog in
Avatar of jenjenut233
jenjenut233

asked on

Need PHP help parsing CGI response...

http://pastie.org/294866

I have a form that submits to a PHP script which in turn does a shell_exec to a perl script written by someone else, which calls an API to validate the form data. The pastie is the exact response I am given when a user is not authenticated. This should be very easy for someone to figure out, but I'm on a time crunch to get this done by end of day so I need to know how to parse out each field.

Specifically, at the bottom of the response is a 'data' => '0' -- it could potentially be '1' but that shouldn't matter for these purposes. However, I want to be able to know what that value is. I also want to know what the value of the errors[{'messages'}] is *if* it exists (sometimes it won't be there, that's ok).

So in essence, I want to be able to say if (blah['data'] == '0') then do something otherwise do something else.

TIA,
Jen
<?php
$output = shell_exec('login.pl test test');
// echo $output gives: 
$VAR1 = bless( {
  'warnings' => [],
  'errors' => [
    {
      'data' => '',
      'message' => 'Customer/password combination is invalid',
      'code' => '1997'
    }
  ],
  '_warn_table' => undef,
  '_err_table' => undef,
  'multicall' => 0,
  'data' => '0'
}, 
'VWH::API::Return');
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$VAR1 ['data'];

$value_data = array_search('data', $VAR1);
if ($value_data == 1){
// DATA == 1
} else {
// DATA == NOT 1
}

$value_data = array_search('data', $VAR1);
if ($value_data == 1){
// DATA == 1
} else {
// DATA == NOT 1
}

Open in new window