Solved

Need PHP help parsing CGI response...

Posted on 2008-10-17
4
296 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:jenjenut233
  • 3
4 Comments
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 500 total points
ID: 22765837
Bless is not a PHP function - it is a PERL/CGI function

http://us.php.net/manual/en/arrayobject.construct.php

Try array function instead:
<?php

$output = shell_exec('login.pl test test');

// echo $output gives: 

$VAR1 = array( {

  '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

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22765859
$VAR1 ['data'];

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

Expert Comment

by:NerdsOfTech
ID: 22765862

$value_data = array_search('data', $VAR1);

if ($value_data == 1){

// DATA == 1

} else {

// DATA == NOT 1

}

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress syntax error 1 29
how to resize preview image 4 32
PHP string issue 5 18
Wordpress Body Class 5 13
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now