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, result shows page not found error.

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

in the hook_menu I gave

$items['edit_details/%'] = array();

i have passed the value into session variable using this

$_SESSION['id'] = $_GET['uid'];
  • Which Drupal version are you using? – No Sssweat Sep 29 '16 at 7:14
  • i am using drupal 7 – ana Sep 29 '16 at 12:30

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.


| improve this answer | |
  • This is not working. – ana Sep 29 '16 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 '16 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 '16 at 9:16
  • 1) I have updated the answer. 2) No, it cannot be done with js event handler. – Milind Kagdelwar Sep 30 '16 at 15:11

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.