I want to get the uid of a logged in user in an external php script. I am using:
chdir("C:/xampp/htdocs/mywebsite");
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$account1 = user_uid_optional_load();
echo $account1;
But it always return :
stdClass Object ( [uid] => 0 [name] => [pass] => [mail] => [mode] => 0 [sort] => 0 [threshold] => 0 [theme] => [signature] => [signature_format] => 0 [created] => 0 [access] => 0 [login] => 0 [status] => 0 [timezone] => [language] => [picture] => [init] => [data] => [roles] => Array ( [1] => anonymous user ) )
irrespective of admin, authenticated or anonymous user. I also tried these but the result remains same.
global $user;
echo $user;
$account1 = user_load(array('name' => check_plain($name)));
echo $account1;
I also checked a similar problem and uncommented $cookie_domain = '';
( blank cookie domain for localhost )in my settings.php but to no avail.
How can I get some non-zero uid for logged in users ?