I am new to write a plugin ..I am having a testplugin.php file and a ajax.php file ..
My code in testplugin.php is
global $session; print_r($abc); //$abc is array of my data .. $session['arrayImg']=$abc; //saving data in session echo $session['arrayImg']; //displayin "Array"
And my ajax.php consists of following code
global $session; $abc = $session['arrayImg']; print_r ("abs== ".$abc); //displayin "abs== Array"
And if use session_start();
I get following error
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
I just want to send array of data from one file of my plugin to another file ...
Sessions are a simple way to store data for individual users against a unique session ID. This can be used to persist state information between page requests. Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data.
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer.
Starting A PHP Session In a standard PHP application, a session would be started using the session_start function at the very top of the PHP script. This may tempt you to open the header. php file in your WordPress theme and add something like the following to begin using sessions.
functions.php
filefunction wpse16119876_init_session() { if ( ! session_id() ) { session_start(); } } // Start session on init hook. add_action( 'init', 'wpse16119876_init_session' );
SESSION
-// If session has started, this data will be stored. $_SESSION['arrayImg'] = $abc;
// handle the ajax request function wpse16119876_handle_ajax_request() { if ( ! session_id() ) { session_start(); } if ( array_key_exists( 'arrayImg', $_SESSION ) ) { $abc = $_SESSION['arrayImg']; } else { $abc = 'NOT IN SESSION DATA'; } // Do something with $abc }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With