I have created a search block. It outputs multiple results (names) as links. User can follow the link. How can I pass the user name into $_SESSION variable?

I tried doing this, the result shows a page not found error.

'name' => l(t($n['name']), 'edit_details' ,array('query' => array('uid' => $n['uid'])))

In hook_menu() I set $items['edit_details/%'] to array(). I passed the value into the session with $_SESSION['id'] = $_GET['uid'];.

  • Which Drupal version are you using?
    – No Sssweat
    Sep 29, 2016 at 7:14
  • i am using drupal 7
    – ana
    Sep 29, 2016 at 12:30

1 Answer 1


You can do like this.

Link URL :

 'name' => l(t($n['name']),'edit_details/@uid', array('@uid' => $n['uid']))

In hook_menu() :

$items['edit_details/%user'] = array(
    'title'          => 'Lets start',
    'page callback'   => '_get_user',
    'page arguments'  => array(1),
    'access callback' => TRUE,
    'type'            => MENU_CALLBACK,

In callback : In callback function you will get complete user object, as this wild card used for user core module.

function _get_user($user) {
  $_SESSION['user_name'] = $user->name;
  //Redirect to any other page you want.


  • This is not working.
    – ana
    Sep 29, 2016 at 11:27
  • The link url should be changed from 'user-check/@uid' to 'edit_details/@uid' so that it matches what is in the hook_menu. Also, don't forget that whenever you add/change a hook_menu you MUST clear your cache
    – bleen
    Sep 29, 2016 at 20:35
  • As I have mentioned it is not working. Can this be done with on click or an event listener.
    – ana
    Sep 30, 2016 at 9:16
  • 1) I have updated the answer. 2) No, it cannot be done with js event handler. Sep 30, 2016 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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