Please help with the code to redirect to logged in user. I have a block with the following link: <a href="user/*" title="iuser">. This link works to show the block on a page but not as link. have also tried <a href="user/%" title="iuser">.

Would like the variable link to go to pages such as: /users/sponsorone or /users/adam or /users/ben if the users are logged in as sponsorone or adam or ben.

Thanks
John

[Edited to add code tags: nevets]

Comments

nevets’s picture

Using html you would use something like

<a href="/user" title="iuser">

this relies on using a text filter that allows the 'a' tag, by default this would be the full html filter.

If you use PHP code you can use

<?php
global $user;
// See if they are logged in
if ( $user->uid ) {
  // Logged in
  print l(t('Visit your profile'), 'user/' . $user->uid);
}
?>

This approach requires the PHP code filter.

vm’s picture

user/* doesn't work as a link because it's not a correct path with the * in there.

<a href="user" title="iuser">

should be enough in most cases. however if you are in a block you may want to use an absolute url rather than a relative so that you don't have to deal with issues that arise if you are multiple levels deep. ie: yoursite.com/somenode/sometitle. The above should work because drupal is smart enough to know that any call to the user path from a logged in user will take that user to their own user page and dynamically add the uid

or generating a menu (which will generate the block) and adding your link that way should also work.

jantico’s picture

Sorry, but neither are working. I tried:
Only local images are allowed.

or
Only local images are allowed.

The code is in a block in Drupal 6.

vm’s picture

you cannot upload images to drupal.org. You must upload to a photosharing site.

jantico’s picture

<a href="user" title="iuser">offer</a>
<a href="/user" title="iuser">offer</a>
<a href="users" title="iuser">offer</a>
<a href="/users" title="iuser">offer</a>

Tried all these as links in a block and returned page not found.

Thanks

John

fjd’s picture

Do you get any error when going to www.mysite.com/user when typed directly into the address bar?
If you can get to the user page OK, what appears in the status bar when you hover over the links in the block?

abhishek sawant’s picture

You can define,

global $base_url;

and make the url somehow like below :

echo $base_url .'/'.'user';

Hope it helps.

Abhishek Sawant
Drupal Developer