Hi, i'm doing a wordpress plugin that add some data from angularjs/json on each post
in the json angularjs request i have to pass the session id
i've found this code to set it

session_start();
$id = session_id();

but i don't know where to put it becouse if i add it in the function that print the data below the article post session_start() gives error where do i have to put the session_id() in a wordpress plugin? thank you for help

you can add it on your plugin or theme function. I don't have any time to actually check for my answer. However, I did this long time ago and this is how much I can recall.

Warning! *Please check the wordpress codex for validity of my wordpress syntax and make sure they are not deprecated. I did this long time ago and I haven't check on their updated documentation.
*
For example, if I have a plugin called veedeoo_plug and I want to register the PHP session for this plugin in wordpress global space, then I would code it something like this.

function my_session(){

     if(!session_id()){

         session_start();
     }
}

## we need to hook the above function with the wordpress.

add_action('init','my_session');

After adding the codes above, check if there are any errors. If no errors you can assign the session as you would assign them on regular php

$_SESSION['your_session'] = 'foo_bar';

for the add_action reference, please read here.

commented: nice work! +4

thank you yes this is the way in wordpress
later i'll tryed to make a more secure system with this tutorial
Click Here
bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.