Zen Cart Logo
Forums / General Questions / log off link - how do I make it only appear when logged on?

log off link - how do I make it only appear when logged on?

Locked

Views: 2,961

Results 1 to 20 of 24
This thread is locked. New replies are disabled.
24 Mar 2008, 6:29 PM
#1
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

log off link - how do I make it only appear when logged on?

Hi,

Right now I have Log Off as permanent link in the nav bar. But how do I make that link only appear if someone is actually logged on?

Thanks!

25 Mar 2008, 4:14 PM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

What did you do to get it to display as a permanent link in the first place?

26 Mar 2008, 3:52 AM
#3
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

It is in ezpages (page title Logoff) with yes to appear in the header and footer and an internal link to the logoff page.

What I would like to do is only have that link appear if someone is actually logged on.

Thanks.

26 Mar 2008, 7:45 AM
#4
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: log off link - how do I make it only appear when logged on?

You can surround the code for that link with an if test like

if ($_SESSION['customer_id']) {
... link code ...
}

26 Mar 2008, 3:25 PM
#5
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

Cool. Where do I put that bit of code?

 
if ($_SESSION['customer_id']) {
index.php?main_page=logoff
} 

Thanks

26 Mar 2008, 3:50 PM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: log off link - how do I make it only appear when logged on?

Actually it may be a bit tricky.

You would put the if test around the entire code that outputs the link, not just the url snippet; but since this is an ez-pages menu, it is dynamic and there is not a fixed bit of code in the file to apply the switch to.

It might work to test the page ids as they are being processed by the output file(s) and skip the output if the current id is the same as the logoff page id. More research needs to be done for this.

26 Mar 2008, 4:19 PM
#7
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

Whoa... that sounds quite a bit more tricky. I was hoping I could just do something similar to the view cart and checkout now links which only appear the nav bar if something is placed in the cart...

Still, it seems like a handy piece of code (having log off only appear if someone is actually logged on)...

Thanks.

26 Mar 2008, 4:39 PM
#8
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: log off link - how do I make it only appear when logged on?

That code would be easy to apply to any element in the header navbar, because the link code is individually spelled out in the file. It is the same principle as is currently used in the header navbar area. Unfortunately, #navCatTabs and #navEZPagesTop are dynamic.

26 Mar 2008, 6:21 PM
#9
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

Yeah I can see where that might throw a wrench in the works. Oh well... it was a good thought. :-)

Thanks.

26 Mar 2008, 8:00 PM
#10
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,603
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

What's the URL?

27 Mar 2008, 4:33 PM
#11
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

the url is www.allk-9.com

the log off link we have been discussing is in the nav bar.

it is a permanent link (via ezpages).

was hoping to have that link only appear if somone was actually logged on. similar to how the view cart | checkout now links only appear if there is an item in the cart.

thanks.

27 Mar 2008, 4:58 PM
#12
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,603
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

Do you want the default behavior of showing the login link if not logged in? and showing the My Account link along with the logoff link?

27 Mar 2008, 5:03 PM
#13
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

well my login link is actually titled order tracking which can also been seen in the nav bar.

yes i want the order tracking (aka login) link to always be visible. so if someone clicks on order tracking, it takes them to the login screen. then if they actually login, that is when i would like the log off link to appear (only if they have logged in).

thanks.

27 Mar 2008, 5:11 PM
#14
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,603
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

If they are logged in - shouldn't the Order tracking link take them to their account?

27 Mar 2008, 5:28 PM
#15
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: log off link - how do I make it only appear when logged on?

The link is not in the navbar, but in the ez-pages header bar. (The navbar is where you put the Dog Agility etc. links.)

You can edit /includes/modules/your_template/tpl_ezpages_bar_header.php and use the if test around the <a> output line.```php

<div id="navEZPagesTop"> <?php for ($i=1, $n=sizeof($var_linksList); $i<=$n; $i++) { ?> <a href="<?php echo $var_linksList[$i]['link']; ?>"><?php echo $var_linksList[$i]['name']; ?></a><?php echo ($i < $n ? EZPAGES_SEPARATOR_HEADER : '') . "\n"; ?> <?php } // end FOR loop ?> </div> ``` Add

if ($_SESSION['customer_id'] or ($var_linksList[$i]['name'] != 'Logoff')) { //show Logoff only if logged in ?>

and

} // /if

as shown to get

<div id="navEZPagesTop">
<?php for ($i=1, $n=sizeof($var_linksList); $i<=$n; $i++) {
  if ($_SESSION['customer_id'] or ($var_linksList[$i]['name'] != 'Logoff')) { //show Logoff only if logged in ?>
  <a href="<?php echo $var_linksList[$i]['link']; ?>"><?php echo $var_linksList[$i]['name']; ?></a><?php echo ($i < $n ? EZPAGES_SEPARATOR_HEADER : '') . "\n"; ?>
<?php  } // /if
 } // end FOR loop ?>
</div>
27 Mar 2008, 5:38 PM
#16
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: log off link - how do I make it only appear when logged on?

Since you have removed the automatically-switching login and my account links from the original navbar, you could use a modification of the logic above to hide the login link and show the my account link when logged in.

If the login link is named "Order Tracking", you may be able to use "Order Tracking" for the my account link so the code would distinguish between the names but there would be no visible difference.

27 Mar 2008, 6:02 PM
#17
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,603
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

Glenn - What I was trying to get to was you don't need any custom code - you can use the login/loggof/myaccount section of the navBar beside the ezpages links - but y'all figure it out.

27 Mar 2008, 6:13 PM
#18
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: log off link - how do I make it only appear when logged on?

Yep, it would be easier to use all of the original code in another section of navbar... the original question was easily addressed with that bit of code, but increasing the workload on it changes the balance.

27 Mar 2008, 8:04 PM
#19
gsdcypher avatar

gsdcypher

Totally Zenned

Join Date:
Feb 2007
Posts:
816
Plugin Contributions:
0

Re: log off link - how do I make it only appear when logged on?

Whoa... wait ya'll lost me. :blink:

I realize I have probably made a mess of things due to my limited knowledge... but I am trying.

It appears to me that Glenn has it sussed out. Any custom code that has re-invented the wheel is certainly my doing.

This much I understand and can do in the /includes/modules/your_template/tpl_ezpages_bar_header.php:
```

<div id="navEZPagesTop">
<?php for ($i=1, $n=sizeof($var_linksList); $i<=$n; $i++) { ?>
<a href="<?php echo $var_linksList[$i]['link']; ?>"><?php echo $var_linksList[$i]['name']; ?></a><?php echo ($i < $n ? EZPAGES_SEPARATOR_HEADER : '') . "\n"; ?>

<?php } // end FOR loop ?>

</div>

 
Lost me on this part (but it sounds very cool):
> If the login link is named "Order Tracking", you may be able to use "Order Tracking" for the my account link so the code would distinguish between the names but there would be no visible difference.
 
Have my modifications made it too conviluted or should we do something different? > Yep, it would be easier to use all of the original code in another section of navbar... the original question was easily addressed with that bit of code, but increasing the workload on it changes the balance.
 
Thanks.
27 Mar 2008, 9:02 PM
#20
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: log off link - how do I make it only appear when logged on?

The code snippet you reference is part of the stock file. The second code block in my post above is the alteration for hiding your logoff link.

The "name" distinction is about using the "non-breaking space" character (HTML code  ), which is technically different from the common spacebar space.

At any rate, your best bet is to copy from the original tpl_header.php the navMainHeader code for the links, and possibly put them in a new div in your copy of the file. This new div can go next to the ez-pages bar and be styled to look the same, so you can easily have the correct functions.