Forums / General Questions / Require Login for one EZ Page?

Require Login for one EZ Page?

Started by monster_pawn on 6 Dec 2006, 10:14 PM · Views: 8,655

Results 1 to 20 of 27
6 Dec 2006, 10:14 PM
#1
monster_pawn avatar

monster_pawn

New Zenner

Join Date:
Nov 2006
Posts:
6
Plugin Contributions:
0

Require Login for one EZ Page?

A new zenner with my first question! Not sure what section thsi should be posted under, so I'm starting here.

Incidentally, this forum has been FANTASTIC so far and I've found an answer to nearly every question I've had, but I can't find this one.

I'm a designer who just took my first store site live, and so far eveything is working great. But I'm wondering if there is a way to require a customer to login/create an account to access just ONE of the EZ pages I have set up (In Store Coupons! page). We have coupons that can be printed and use in our brick and mortar store, and I'd like to require customers to set up an account before accessing the coupons. I don't want people to have to login to see the other EZ pages.

I'm guessing it's an " if ($_SESSION..." statement placed somewhere, but my overall knowledge of php is very limited - anyone have suggestions?

And any other site critique is appreciated also...

Thanks
R Fish

http://monsterpawn.com

7 Dec 2006, 12:28 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Require Login for one EZ Page?

/includes/modules/pages/page/header_php.php
around line 23 you'll see:

if ($ezpage_id == 0) zen_redirect(zen_href_link(FILENAME_DEFAULT));

Right below that, insert the following code, substituting '55' with the number of the page to 'protect':```
if ($ezpage_id == 55) {
if (!$_SESSION['customer_id']) {
$_SESSION['navigation']->set_snapshot();
zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
}
}

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 Jun 2009, 2:49 PM
#3
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: Require Login for one EZ Page?

You could instead follow the advice of post 7 on this thread: allow php inside ezpages

and then put this in any ezpage to allow more than one "members only" page without needing to edit the header_php.php file for each one.

<?php
if ($_SESSION['customer_id']) {
echo('You are signed in and have access to the members only area.');
}else{echo('You are not signed in, and do not have access to the members only area.');}
?>

(In case it isn't obvious, put your members only content where I have the first echo, and replace the second echo if you want a different message to ask them to sign in.)

24 Feb 2010, 10:21 PM
#4
kromero avatar

kromero

New Zenner

Join Date:
Feb 2010
Posts:
6
Plugin Contributions:
0

Re: Require Login for one EZ Page?

In the code:

<?php if ($_SESSION['customer_id']) { echo('You are signed in and have access to the members only area.'); }else{echo('You are not signed in, and do not have access to the members only area.');} ?>

Is it possible to specify a specific customer_id ? Like only show this page to customer id # 1?

Thanks,
Kristina

25 Feb 2010, 1:51 AM
#5
kromero avatar

kromero

New Zenner

Join Date:
Feb 2010
Posts:
6
Plugin Contributions:
0

Re: Require Login for one EZ Page?

I did it! For those who would like to know how to hide a page for logged in members AND only give access to a select member or members.

Insert this in an ezpage: (to learn how to insert php in an EZpage, look at the link above)

<?php if ($_SESSION['customer_id'] == "1" ) { echo('Access.'); }else{echo('You are not signed in, and do not have access to the members only area.');} ?>

Change number "1" to the customer number you want to have access to the page. You can find your customer number by going to "customers" in the admin section of your Zen Cart. The number is right next to the listing.

Obviously, change the echo'' to the statement you want your logged in member to see.

16 Oct 2010, 3:39 AM
#6
gabman21 avatar

gabman21

New Zenner

Join Date:
Oct 2006
Posts:
1
Plugin Contributions:
0

Re: Require Login for one EZ Page?

I have the site set up so a customer must login to see the products, but this also locks them from the ezpages is there a way to allow new customers that have not set up an account to view the ez pages?

18 Feb 2011, 10:36 PM
#7
lacktorium avatar

lacktorium

New Zenner

Join Date:
Feb 2011
Posts:
6
Plugin Contributions:
0

Re: Require Login for one EZ Page?

how can you add more that one id

19 Feb 2011, 1:52 AM
#8
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Require Login for one EZ Page?

not sure this is the right code but it works.

<?php if ($_SESSION['customer_id'] == "1" ) { if ($_SESSION['customer_id'] == "4" ) { echo('Access.'); echo('You are signed in and have access to the members only area.'); }else{echo('You are not signed in, and do not have access to the members only area.');} ?>

have to keep duplicating 'if' statement

19 Feb 2011, 2:03 AM
#9
lacktorium avatar

lacktorium

New Zenner

Join Date:
Feb 2011
Posts:
6
Plugin Contributions:
0

Re: Require Login for one EZ Page?

thx i wasn't sure it that would work, ill use it unless something else works better. im not as fluent in php yet i think it mite be possible to do an array. but i could be wrong.

19 Feb 2011, 2:31 AM
#10
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Require Login for one EZ Page?

disregard first post, try this:

<?php if (in_array($_SESSION['customer_id'],explode(",",'1,4')) ) { echo('Access.'); echo('You are signed in and have access to the members only area.'); }else{echo('You are not signed in, and do not have access to the members only area.');} ?>

separated_by_commas,and_no_spaces

19 Feb 2011, 4:12 AM
#11
lacktorium avatar

lacktorium

New Zenner

Join Date:
Feb 2011
Posts:
6
Plugin Contributions:
0

Re: Require Login for one EZ Page?

thank that works perfectly. quick question tho is echo('Access.'); necessary?

19 Feb 2011, 4:20 AM
#12
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Require Login for one EZ Page?

no, I not even sure why its there, it could have been

<?php if (in_array($_SESSION['customer_id'],explode(",",'1,4')) ) { echo('Access. You are signed in and have access to the members only area.'); }else{echo('You are not signed in, and do not have access to the members only area.');} ?>
2 Mar 2011, 6:01 PM
#13
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: Require Login for one EZ Page?

rbarbour,
Always glad to learn something new. I like the way you used "in_array" and used the output from "explode" without assigning it to a variable. I might not have considered that option.

2 Mar 2011, 6:27 PM
#14
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Require Login for one EZ Page?

I know very little php, I know it worked, I don't know if it is the right way. Someone with a little more knowledge may be able to show an alternate option or way of doing it.

26 May 2012, 3:11 PM
#15
grantopt avatar

grantopt

New Zenner

Join Date:
May 2012
Posts:
36
Plugin Contributions:
0

Re: Require Login for one EZ Page?

I am trying to combine restrictions to ez pages based on ez page id and customer id. For example, I have 2 ez pages with id1 and id2. And 4 customers id1-id4. I want to restrict:

ez page id 1 for only customer id 1 and 2
ez page id 2 for only cusotmer id 3 and 4

This is what I have, but does not work. Is it possible to restrict 2 ways or only 1 way?

if ($ezpage_id == 1) {
if ($_SESSION['customer_id'] == "1" ) {
if ($_SESSION['customer_id'] == "2" ) {
    $_SESSION['navigation']->set_snapshot();
    zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  }
}


if ($ezpage_id == 2) {
if ($_SESSION['customer_id'] == "3" ) {
if ($_SESSION['customer_id'] == "4" ) {
    $_SESSION['navigation']->set_snapshot();
    zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  }
}

Thanks

26 May 2012, 3:19 PM
#16
ajeh avatar

ajeh

Oba-san

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

Re: Require Login for one EZ Page?

You are blocking your self with your code ...

Are you trying to make ezpage_id 1 only available to customers_id 1 and 2?

Are you trying to make ezpage_id 2 only available to customers_id 3 and 4?

What happens if the customer_id is 7 and they try to get to ezpage_1 ... where should they go?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

26 May 2012, 11:42 PM
#17
grantopt avatar

grantopt

New Zenner

Join Date:
May 2012
Posts:
36
Plugin Contributions:
0

Re: Require Login for one EZ Page?

Ajeh:

You are blocking your self with your code ...

Are you trying to make ezpage_id 1 only available to customers_id 1 and 2?

Are you trying to make ezpage_id 2 only available to customers_id 3 and 4?

What happens if the customer_id is 7 and they try to get to ezpage_1 ... where should they go?

Bad on my part to not include a little more detail of what I have so far. Right now I have a second site which is only for my partnering distributors. I had to make a second site in a subfolder to make sure that the public cannot access the product prices. One common problem in many mods for previous versions such as "specific categories for specific customers" works, but if you were to change the product_id in the url to another number, it would show for that product, even if it wasn't assigned to them. Pretty much what I have done now is create ezpages with html code for the product info pages which now shows and works when adding to cart. So this leads to restricting the pages for certain distributors.

I have my site using the setting in Admin-Config-Customer Details, both must login to browse and authorization both set to 1.

Right now I only have 2 ezpages and 4 customers, which after I figure this coding out, I will use it to expand it to more ezpages and add the additional customers manually.

Yes exactly, I only want those particular customers allowed to access the ezpage. So in the case of customer_id 7, they will be routed to a custom page I made saying the page is restricted (filename page_restricted).

Thanks Ajeh

27 May 2012, 2:14 AM
#18
ajeh avatar

ajeh

Oba-san

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

Re: Require Login for one EZ Page?

What I did was make an Ezpage with no setting for Sort Order, that is ezpage_id 17 in this code, and when someone logs in that is not allowed on the page based on $_SESSION['customer_id'] they are sent to this EzPage for ezpage_id 17 which reads that they are not a member ...

I customized the code in:
/includes/modules/pages/page/header_php.php

and added the code in RED to control when the customer is not logged in and when the customer is allowed or not allowed to get to their EZPage ...

$chapter_id = (int)$_GET['chapter'];
$chapter_link = (int)$_GET['chapter'];

//die('I SEE ' . $ezpage_id . ' - ' . $group_id);
//die('I SEE ' . $ezpage_id . ' - ' . $chapter_id);

// bof: ezpages ezpage_id 16 only for customers_id 2 & 7 go to ezpage_id 17 if not correct customer when logged in
if ($ezpage_id == 16) {
  if (!$_SESSION['customer_id']) {
    $_SESSION['navigation']->set_snapshot();
    $messageStack->add_session('header', 'Please login to access Member\'s area', 'caution');
    zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  }
  if ($_SESSION['customer_id'] != 2 && $_SESSION['customer_id'] != 7) {
    $messageStack->add_session('header', 'Sorry you do not have access to Member\'s area', 'caution');
    zen_redirect(zen_href_link(FILENAME_EZPAGES, 'id=17', 'NONSSL'));
  }
}
// eof: ezpages ezpage_id 16 only for customers_id 2 & 7 go to ezpage_id 17 if not correct customer when logged in

$var_pageDetails = $db->Execute("select * from " . TABLE_EZPAGES . " where pages_id = " . (int)$ezpage_id );

In this case, the ezpage_id they are trying to get to is ezpage_id 16 ...

If not logged in, they are asked to login before anything ...

Once logged in, the $_SESSION['customer_id'] is tested and if NOT customers_id 2 or 7, they are sent to the ezpage_id 17 and told they are not a member ...

If they are customers_id 2 or 7 then they can go on to ezpage_id 16 ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 May 2012, 5:21 AM
#19
grantopt avatar

grantopt

New Zenner

Join Date:
May 2012
Posts:
36
Plugin Contributions:
0

Re: Require Login for one EZ Page?

Ajeh:

What I did was make an Ezpage with no setting for Sort Order, that is ezpage_id 17 in this code, and when someone logs in that is not allowed on the page based on $_SESSION['customer_id'] they are sent to this EzPage for ezpage_id 17 which reads that they are not a member ...

I customized the code in:
/includes/modules/pages/page/header_php.php

and added the code in RED to control when the customer is not logged in and when the customer is allowed or not allowed to get to their EZPage ...

$chapter_id = (int)$_GET['chapter'];
$chapter_link = (int)$_GET['chapter'];

//die('I SEE ' . $ezpage_id . ' - ' . $group_id);
//die('I SEE ' . $ezpage_id . ' - ' . $chapter_id);

// bof: ezpages ezpage_id 16 only for customers_id 2 & 7 go to ezpage_id 17 if not correct customer when logged in
if ($ezpage_id == 16) {
if (!$_SESSION['customer_id']) {
$_SESSION['navigation']->set_snapshot();
$messageStack->add_session('header', 'Please login to access Member's area', 'caution');
zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
}
if ($_SESSION['customer_id'] != 2 && $_SESSION['customer_id'] != 7) {
$messageStack->add_session('header', 'Sorry you do not have access to Member's area', 'caution');
zen_redirect(zen_href_link(FILENAME_EZPAGES, 'id=17', 'NONSSL'));
}
}
// eof: ezpages ezpage_id 16 only for customers_id 2 & 7 go to ezpage_id 17 if not correct customer when logged in

$var_pageDetails = $db->Execute("select * from " . TABLE_EZPAGES . " where pages_id = " . (int)$ezpage_id );

> 
> In this case, the ezpage_id they are trying to get to is ezpage_id 16 ...
> 
> If not logged in, they are asked to login before anything ... 
> 
> Once logged in, the $_SESSION['customer_id'] is tested and if NOT customers_id 2 or 7, they are sent to the ezpage_id 17 and told they are not a member ... 
> 
> If they are customers_id 2 or 7 then they can go on to ezpage_id 16 ...

Awesome.  I thank you for the coding and it works like a charm.  Much simpler to use an ezpage for a restricted page, tested and works perfectly now.
27 May 2012, 1:44 PM
#20
ajeh avatar

ajeh

Oba-san

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

Re: Require Login for one EZ Page?

Thanks for the update that this is working for you ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!