0

I want to make a customized query page based on the user who is logged in. The query page is a node made in custom made content type "query"(this content type has no additional fields than which are created in a new default content type)

I have a <p id = my_para> tag in my node. I call an external query.js script in my node which uses xmlHTTPRequest to call an external query.php. This php connects with mysql and does a query like

select * from my_table where user = "logged-in-user";

and returns the query result using json_encode back to query.js. The query.js parses json and displays it on my node using document.getElementById("my_para").innerHTML = my_parsed_json_variable

So I some how want to get the logged in user details(there can be many logged in users to mysite at the same time) so that each user can see a custom page through these scripts.

How can I get the user details in my external query.php ? I tried using these in my query.php

global $user;
$name = $user->name;
$id = $user->uid;

But it gives

Trying to get property of non-object in C:\xampp\htdocs\mywebsite\sites\all\themes\danland\query.php

1

If your page is being created via code, then you can check the role of the user via code and not display the filters you want.

Otherwise, you may want to create different query pages for different roles and enable the right page for the right role using a module that restricts access such as the 'node access' module.

  • I have updated the question to provide more clarity to my question. I cannot use nodeaccess module here as all clients belong to the same role and are ever increasing in number. I want to get the details of the logged in user through some bulid in functions and how to use them in my script. – Utsav Sinha May 22 '14 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.