Zen Cart Logo
Forums / General Questions / How to get user name display on every page?

How to get user name display on every page?

Views: 1,042

Results 1 to 5 of 5
12 May 2014, 3:31 PM
#1
sarahl avatar

sarahl

Zen Follower

Join Date:
May 2004
Location:
UK
Posts:
471
Plugin Contributions:
0

How to get user name display on every page?

I am trying to get "Hi <users name> " in the header of my shop - along the lines of the logout/account button - trying to make it more personal

So it would Say

Hi Sarah | Your Account | Your Basket £2.00 5 items

But I have no idea how I can get that "name" inserted? Tried various firstname php calls and none work - I can see %s is used for the "greet user" section - but doesn't copy across either

Thanks
Sarah

12 May 2014, 3:41 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to get user name display on every page?

You could use the session variable:
$_SESSION['customer_first_name']

12 May 2014, 3:52 PM
#3
sarahl avatar

sarahl

Zen Follower

Join Date:
May 2004
Location:
UK
Posts:
471
Plugin Contributions:
0

Re: How to get user name display on every page?

Thank you sometimes I am truly thick :) the only thing I didn't try!

Is there a list/detail of what details we have stored in the sessions?

12 May 2014, 4:16 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to get user name display on every page?

You could add, temporarily to the:
/includes/templates/template_default/common/tpl_header.php

the code in RED:

[B]<?php
echo '<pre>'; echo print_r($_SESSION); echo '</pre>';
?>
[/B]<?php
  // Display all header alerts via messageStack:

NOTE: check if you have:
/includes/templates/your_template_dir/common/tpl_header.php

as an override and if you do add it there ...

Then, login and you can see the $_SESSION variables that exist ...

13 May 2014, 3:12 PM
#5
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: How to get user name display on every page?

SarahL:

I am trying to get "Hi <users name> " in the header of my shop - along the lines of the logout/account button - trying to make it more personal

So it would Say

Hi Sarah | Your Account | Your Basket £2.00 5 items

But I have no idea how I can get that "name" inserted? Tried various firstname php calls and none work - I can see %s is used for the "greet user" section - but doesn't copy across either

Thanks
Sarah

Just to add some formatting, this site http://torontogoldsilver.com/ uses this code:

includes/templates/YOUR_TEMPLATE/common/tpl_header.php

<div class="headerGreeting"> <?php if ($_SESSION['customer_id']) { echo 'Hello ' . $_SESSION['customer_first_name'] . '!'; } else { echo 'Welcome!'; }?> </div>

This shows 'Welcome!' for guests and once you're logged in adds 'Hello (First Name)'

You can then set the CSS style for .headerGreeting as you wish.