Problem when visiting users profiles In my website, users can connect, see their profiles, update their profiles and visit other users profiles

So for each users, I created a profile page user-profile.tpl.php

But I've some troubles when I'm visiting other users account. 

For example in my account profile page, there is a link who's redirecting me to the edit page.

I wrote this code for showing the edit link : 

&lt;?php
  global $user;
  print l(t('Update my profile'), "user/{$GLOBALS['user']-&gt;uid}/edit");
?&gt;


When I'm visiting a random user page, this link appears. But I want it to appear only on my profile page

And it's the same for my profile picture, when I'm visiting a random user page, my picture is always showing.

&lt;?php 
    $user_item = user_load_by_name($user-&gt;name); // or user_load( $user-&gt;uid )
    print theme('user_picture', array('account' =&gt;$user_item));
?&gt;


I have no idea how to fix theses problems, that's why I need your help (I'm new to Drupal btw)

(I'm using Profile2)

Thanks
You can get the user id from url using arg() function. for the first part you can do something like this.

global $user;
$user_id = arg(1);
if($user-&gt;uid == $user_id) {
// means it is logged in user profile - so show edit link


}


For the second part you are loading profile of logged in user, that is why it is always showing your picture you need to do the following instead.

$user_item = user_load($user_id); // user id we got from arg()
print theme('user_picture', array('account' =&gt;$user_item));