0

I need an array in multiple pages, so I tried to make a php file where the array is printed. I used:

file_put_contents('file.php',
    '<?php $order = ' . var_export($order1, true) . '; ?>');

I was hoping that if I included this file in the files where I need the array, I could use it as $order, but I get an error instead. I checked file.php and everything looks in order. Does anyone knows what I am doing wrong?

1 Answer 1

1

You should not create .php files by your backend. It is not secure. I recommend you to use JSON for that:

      file_put_contents('file.json',json_encode($order1));
      $order = json_decode(file_get_content($url), true);

And you should hide this files from web in your .htaccess or by another available method for secure purpose.

Sign up to request clarification or add additional context in comments.

3 Comments

array $order1 is a multidimensional array containing objects, is it possible that the objects become arrays after the decode? Because I can't recall $idA = $order1[$Q][0]->id; anymore.
$order = json_decode(file_get_content($url), false); but everything will be an object (last parametr in json_decode goes to false)
Also you can use "serialize" not the json_decode: file_put_contents('file.json', serialize($order1)); $order = unserialize(file_get_content($url));

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.