user id which initiated script

I'm developing a website on wordpress platform. I have strange issues caused by user id. It is this the user who initiated the script:

global $user_ID; 

what i mean is, when somebody go to a page, and php executes, so i need to know the user id in php when code executes. For some reasons, sometime the id is not right.

also when php script is executing , if i do:

global $user_ID =  get_current_user_id();

then i have the user id which initiated this script ?

Solutions

The issue was in strpos(), this is not a smart function, it not able to find a substring:

strpos($text,'{"user":"'.$user_ID.'","status":"2"}');

But substr_count() worked. And this is not my first time when strpos() fault... i will no more use it.

Similar questions

How to tell which database tables belongs to which multisite site
I have a local multisite installation I use for development with a relatively large number of sites set up. Every site has its own numbered database tables (i.e. wp_n_links, wp_n_options, wp_n_postmeta etc.) Every time I need to look at a database table in phpMyAdmin I have to look through all the wp_n_options tables to find the tables for the site...
Which url points to which file
Actually i have deployed a wordpress running website on my local environment. I want to have some general instruction that how can i know which file points to which url. Like if i entered the url mysite.com/household-insrtuments. it opens a page in the backend i searched from the text through the project i found that this opens the file name 'housi...
Using polylang, how can I see which post is the "original" and which are the "translated children"?
I am using Polylang. It is not obvious to me how the relationship between posts are established. I can switch between different language versions of the same post, and I can tell that they're (obviously) different posts in the database. But I can see how Polylang establishes and maintains that relationship. I assumed that there was some meta-value,...
WordPress: different WP_Query usage: Which is correct, in which context?
I have been creating custom WordPress loops with two different approaches, both which involve creating a new instance of the WP_Query object. I typically have multiple loops on a single page. I do not understand how these two approaches differ, and which is the correct context to use each. Approach 1: http://codex.wordpress.org/Class_Reference/WP_Q...
Wordpress : How to programmatically GET (to know) which Sidebar (or) which Menu is being used on Different Pages?
Lets say i want to detect such thing from the "functions.php" .. to know which Sidebar (or) which Menu is being loaded on current (whatever landed) page, how can i know? Lets say i have a few pages, with: From functions.php, if: So the thing here is: How to simply do it please.
How to check which coupon is applied to which product in WooCommerce?
Since we can apply different coupons to each product in an order, Is there any method to know which coupon is applied to which product? I've used $order->get_used_coupons() function but it just returns the used coupon codes only. Please help with a solution. Thanks.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.