I haven’t touched PHP in years and have been asked to create an wordpress plugin. I’m trying to figure out the “correct” way to do the following:
page1.php
---------
some_plugin(array(
'option1' => 'some_data',
'option2' => 'http://do_not_expose_to_client/'
});
generates
---------
<script language="text/javascript">
$.get('/page2.php', { data_set : 1 });
</script>
page2.php
---------
var options = get_options_from_page_1( $_GET['data_set'] );
Make sense I hope? Basically I want to pass a PHP array from page1 –> page2 and am looking for a clean mechanism to do so. I know I can drop data in a session var, but that just seems hacky and if I have multiple instances of this plugin on the page, I need to start tracking instance IDs, etc.
This is basically a PHP “problem”. Each script is executed in it’s own process in your example and these do not share data.
An easy way to do so would be infact using
$_SESSION, and you’re right you must manage the data on your own. But you must so with any other method (e.g. via the database). I think session is pretty handy then.Another method would be to encrypt the data, pass it with the request and then decrypt it again.