0

Hi I'm having an issue where I try and pass a JSON Array through a url to another page and then retrieve the value using $_REQUEST. I've looked at other similar issues here and tried to get it working using http_build_query but still having issues and hoping someone can help me out.

This is the Array containing a JSON object I am trying to pass through. This array is contained in the variable $validationReport:

Array([0] => stdClass Object([resourceUri] => file:/home/testFile.txt#//@statements.12/@typeList.0/@enumLiterals.11 [severity] => WARNING [lineNumber] => 333 [column] => 9 [offset] => 7780 [length] => 24 [message] => Name should be less than 20 characters))

This is the url I have built:

<a href='../../validationReport.php?fileName=$fileName&fileSize=$fileSize&validationReport=$validationReport' target='_blank'>View Validation Report</a>

I'm trying to use these values on a different page and I'm using the following code to retrieve the values:

 if (isset($_REQUEST['fileName']) && isset($_REQUEST['fileSize']) && isset($_REQUEST['validationReport'])) {
    showReport($_REQUEST['fileName'], $_REQUEST['fileSize'], $_REQUEST['validationReport']);
 } 

Both fileName and fileSize are set fine and I can get their values but the $_REQUEST['validationReport'] is never set. Can anyone help me to figure out how to pass this value through the URL so that the $_REQUEST['validationReport'] will contain the Array with the JSON Object above.

1 Answer 1

4

You cannot send an object or display it on webPath

Try this:

json_encode(); to encode it to string

<a href='../../validationReport.php?fileName=$fileName&fileSize=$fileSize&validationReport=json_encode($validationReport[0])' target='_blank'>View Validation Report</a>

then decode it back to object

showReport($_REQUEST['fileName'], $_REQUEST['fileSize'], json_decode($_REQUEST['validationReport']));
Sign up to request clarification or add additional context in comments.

2 Comments

Hi thank you for your help, I've tried this but it is still not being recognised as set by the json request. I've encoded it using json_encode and I've passed that value through but no luck with the $_REQUEST['validationReport'] being set.
The one you have to encode is $validationReport[0] not $validationReport

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.