1

Currently, I am developing a site where I need to add the username to the URL after users log in. I am using the Login destinations module. Usually, users aren't redirected, but they stay on the page they were before logging in, with few exceptions. This unfortunately has to stay, so I cannot redirect them to users/username.

I need to add the username to the URL after users log in. For example, not logged-in users will be at content/main-article; logged-in users will be at content/main-article?username.

I tried that with the Menu tokens module, but the tokens aren't replaced. A relative URL like node/1 becomes node/1/%5Buser%3Aname%5D.

If you ask why, it is for Piwik to easily recognize logged-in users.

2

2 Answers 2

0

I am not sure how and where you append the username, but I assume that you try something like this:

$url = $current_url . '?user=name';

Instead you should try something like this:

$url = url($current_url, array('query' => array('user' => 'name')));

This will produce this URL: current_url?user=name

Another thing: You have %5B and 3%A in your URL. I am not sure, but you want to have your URL look like this: url[user:name]. Queries in URLs should rather look like I did that and how Drupal's query options creates them: url?user=name

If that does not solve it, you could post some code ;)

Cheers, j

2
  • I think we are not understanding each other, i am trying this: imagine i am user with username lukas and i want all my urls to look like content/main-article1?lukas, content/main-article2?lukas etc. but thank you for your help
    – Lukas
    Commented Aug 29, 2014 at 14:20
  • Well that looks complicated to me. You could try to use preprocess functions to get all links and append the username there. But if you want to get data from the currently logged in user in your code, you could also user global $user;.
    – schlicki
    Commented Oct 14, 2014 at 14:48
0

eventually i managed to do that with the menu tokens, by using current user mail with syntax like this node/1?[current-user:mail] and by setting method for users to random user it works like a charm and email is better for recognizing user anyway ... Thanks guys for help.

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.