Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Want to password protect certain pages


Guest

Recommended Posts

Aloha,

I want to password protect certain pages. My Dedicated Server Manager gives me the option to protect a folder, but because I am protecting different pages in the oscom shopping cart, they are not all in the same folder.

 

A - is there a way to protect just certain files?

 

B - if not, is there an easy way to reroute oscom files to a folder?

 

Appreciate your help!

:D

Link to comment
Share on other sites

Assuming your running apache, I's use .htaccess

 

you can either protect an entire directory with something like:

 

AuthUserFile /path/to/.htpasswd

AuthType Basic

AuthName "Password Protected"

<Limit GET POST>

order deny,allow

require valid-user

</Limit>

 

, or to names files only with:

 

 

<Files yoursecretfile.php>

order deny,allow

deny from all

require valid-user

</Files>

 

Look up .htaccess on the web or in the Apache manual

Link to comment
Share on other sites

3 Questions

 

1) Using .htaccess to protect files, would a "logged-in" member be allowed access to my .htaccess protected files, or would a popup instruct them to login?

 

2) Would I have to make a seperate .htaccess for each file I want to protect or can additional files be added to the primary .htaccess?

 

3) Could this type of .htaccess file be used to protect ".htm" pages....?

 

 

My task at hand is to create a directory that only logged-in members have full access to.....but block anonymous users.

 

 

Assuming your running apache, I use .htaccess

 

you can either protect files only with:

 

<Files yoursecretfile.php>

order deny,allow

deny from all

require valid-user

</Files>

Link to comment
Share on other sites

If you want logged in customers to see a page but not anyone else, use this code:

  if (!tep_session_is_registered('customer_id')) {
   $navigation->set_snapshot();
   tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
 }

Hth,

Matt

Link to comment
Share on other sites

Cool! This may just work for what I need.

 

Do I install this into application_top.php?

 

Thanks!

Link to comment
Share on other sites

God, I feel dense

 

if (!tep_session_is_registered('customer_id')) {

  $navigation->set_snapshot();

  tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));

}

 

Where does the above snippet go?

 

Thanks!

Link to comment
Share on other sites

Somewhere after require('includes/application_top.php') and before the HTML starts. You can look at account.php for an example (I copied the code from there). One usually puts it pretty close to the application_top require (why waste time parsing info before redirecting).

 

If you wanted all your pages to require login, you could change the first line to

 if ((basename($PHP_SELF) != FILENAME_LOGIN) && (!tep_session_is_registered('customer_id'))) {

and put it in includes/application_top.php (after $PHP_SELF is defined and the session is started). Someone posted code that they were using to do this a while ago. You may want to look for that thread if you have trouble.

 

Hth,

Matt

Link to comment
Share on other sites

UPDATE:

 

I copied this script (from account.php - above suggestion by iiinetworks) and pasted it into the top of my new pages that I wanted to give access to only registered members. It worked excellent!

 

if (!tep_session_is_registered('customer_id')) {

  $navigation->set_snapshot();

  tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));

}

 

Clicking on a link without being logged in immediately took the visitor to my LOGIN/Create An Account page, where they could login (or create an account) and it redirected them back to the page they were initially requesting.

 

Thanks, iiinetworks!

 

Now if I can just figure out how to redirect new members from the account signup form straight to PayPal (IPN; recurring membership payment) skipping the shopping cart (because all I am selling are memberships) then redirect back to LOGIN from PayPal, I'll be set.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...