Forced login?

Messages
65
Reaction score
0
Points
6
Hi,

I need to make my main page my account page and create a forced login. I know how to make the main page the login account. I just need to know how to create a forced login for security reasons.

Thanks,

Nicole
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
This is not a hosting support issue; please enter requests like this one into either "Scripts, 3rd Party Apps, And Programming" or "Graphics and Web Design" as appropriate.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
I guess the first questions to ask are what are you using right now and how much do you know about programming? It could be a simple setting in the script you're using, it could mean a simple addition to a script you've written, or it could mean that a major re-write is in order. One can't give directions to a destination without having some idea of the starting point.
 

ace_case

Member
Messages
217
Reaction score
11
Points
18
Forced login? As in a page that can only be accessed if you are logged in? I just have a check to see if there is a user logged in, and if not create a popup and redirect to the login page. You could also extend it to include rank of the member if you need to. Such as
PHP:
if $rank > 2 {
showpage()
}else{
redirect(login.php)
}
(Very pseudo code.)
 
Messages
65
Reaction score
0
Points
6
Forced login? As in a page that can only be accessed if you are logged in? I just have a check to see if there is a user logged in, and if not create a popup and redirect to the login page. You could also extend it to include rank of the member if you need to. Such as
PHP:
if $rank > 2 {
showpage()
}else{
redirect(login.php)
}
(Very pseudo code.)


thanks...where exactly do I place this code? What line and which php file? login php?
 
Messages
65
Reaction score
0
Points
6
Forced login? As in a page that can only be accessed if you are logged in? I just have a check to see if there is a user logged in, and if not create a popup and redirect to the login page. You could also extend it to include rank of the member if you need to. Such as
PHP:
if $rank > 2 {
showpage()
}else{
redirect(login.php)
}
(Very pseudo code.)


I want to make the main page in opencart the login page and make it a force login. ( a private shop) so people can't see anything unless they are logged in. Amazon and Facebook was spying...market research.
 
Messages
65
Reaction score
0
Points
6
Forced login? As in a page that can only be accessed if you are logged in? I just have a check to see if there is a user logged in, and if not create a popup and redirect to the login page. You could also extend it to include rank of the member if you need to. Such as
PHP:
if $rank > 2 {
showpage()
}else{
redirect(login.php)
}
(Very pseudo code.)


It's an exclusive shop for followers of a product...I need the login forced and it not logged in a redicted to the log in before getting to the homepage.
 
Messages
65
Reaction score
0
Points
6
Forced login? As in a page that can only be accessed if you are logged in? I just have a check to see if there is a user logged in, and if not create a popup and redirect to the login page. You could also extend it to include rank of the member if you need to. Such as
PHP:
if $rank > 2 {
showpage()
}else{
redirect(login.php)
}
(Very pseudo code.)

It didn't do anything unless I did it wrong. I added it to the end page of login php. I don't think this code is what I want. I want a redirect to the login if not logged in or you didn't register
 

ace_case

Member
Messages
217
Reaction score
11
Points
18
I have no experience with opencart, but it should be simple enough to do.
Include the code on every page you want protected.
(Theoretical code below)
PHP:
if $isLoggedIn == false {
   echo "<h1>You must be logged in to visit this page.</h1><p>Please login <a href='login.php'>here</a></p>";
   exit()
}
//rest of page
The above code won't automatically redirect, though you could modify it to do so if you wanted. Be sure to put that as soon as you are able to tell if a user is logged in. Also be sure to change $isLoggedIn to the method of checking if a user is logged in.
 
Messages
65
Reaction score
0
Points
6
I have no experience with opencart, but it should be simple enough to do.
Include the code on every page you want protected.
(Theoretical code below)
PHP:
if $isLoggedIn == false {
   echo "<h1>You must be logged in to visit this page.</h1><p>Please login <a href='login.php'>here</a></p>";
   exit()
}
//rest of page
The above code won't automatically redirect, though you could modify it to do so if you wanted. Be sure to put that as soon as you are able to tell if a user is logged in. Also be sure to change $isLoggedIn to the method of checking if a user is logged in.

thanks I will try it :)
 
Messages
65
Reaction score
0
Points
6
I tried and the whole page goes blank...it doesn't show a message or the login page. I copied and pasted your script exactly.
 
Messages
65
Reaction score
0
Points
6
I have no experience with opencart, but it should be simple enough to do.
Include the code on every page you want protected.
(Theoretical code below)
PHP:
if $isLoggedIn == false {
   echo "<h1>You must be logged in to visit this page.</h1><p>Please login <a href='login.php'>here</a></p>";
   exit()
}
//rest of page
The above code won't automatically redirect, though you could modify it to do so if you wanted. Be sure to put that as soon as you are able to tell if a user is logged in. Also be sure to change $isLoggedIn to the method of checking if a user is logged in.

I tried and the whole page goes blank...it doesn't show a message or the login page. I copied and pasted your script exactly.
 

ace_case

Member
Messages
217
Reaction score
11
Points
18
It wasn't made for production. It is a small bit that was meant to lead you in the right direction. I could tell you how I do it, but I am 100% sure it won't work directly for you, since opencart uses a different login system than I do. Try doing exactly this, and tell me what it says.
PHP:
if(!$logged){
  echo "<h1>You must be logged in to visit this page.</h1><p>Please login <a href='index.php?route=account/login'>here</a></p>";
  exit()
}
//rest of page
 
Messages
65
Reaction score
0
Points
6
It wasn't made for production. It is a small bit that was meant to lead you in the right direction. I could tell you how I do it, but I am 100% sure it won't work directly for you, since opencart uses a different login system than I do. Try doing exactly this, and tell me what it says.
PHP:
if(!$logged){
  echo "<h1>You must be logged in to visit this page.</h1><p>Please login <a href='index.php?route=account/login'>here</a></p>";
  exit()
}
//rest of page
where do I place this code? On every page as well?
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
The only place you should have to make a change is in the header.tpl file in the view->theme->template->common directory (that's where it lives in the download; I have no idea what winds up where in the install and am not going to create a local test installation for this question). You'll find the part that needs to be changed here (starting at line # 64 in my download version):

PHP:
<div id="welcome">
    <?php if (!$logged) { ?>
    <?php echo $text_welcome; ?>
    <?php } else { ?>
    <?php echo $text_logged; ?>
    <?php } ?>
  </div>

The part that now says <?php echo $text_welcome; ?> is where you want to put the login link and end the page if the user is not logged in. However, I have to tell you that this is a seriously unfriendly way of going about things, and you won't get any signups if you force registration on landing.
 
Top