I have set category page my default home page.But now i want to show CMS(Home page) for not logged in user while for logged-in i want to show category page.Means how i can set logic that can load both cms pages. How can i do that ? Thanks for any help in advance
<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
load->category page
<?php else: ?>//If user is NOT logged in
Load home page default one
<?php endif; ?>
IF you want only to check condition on home page .You can do like this .Change little bit code for CMS controller like this :
class Mage_Cms_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction($coreRoute = null)
{
if(Mage::getSingleton('customer/session')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('catalog/category/view/id/3'));
}else{
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE);
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultIndex');
}
}
}
Try and inform me about results.Hope this will solve your issue
This might work in your case :
// condition depending on login status of user
if(!$this->helper('customer')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl());
die();
}
else
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('YOUR_CATEGORY_URL'));
die();
}
IF above doesn't work, try this :
$sessionCustomer = Mage::getSingleton("customer/session");
if($sessionCustomer->isLoggedIn()) {
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('YOUR_CATEGORY_URL'));
} else {
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl());
}
Related
What I am trying to do is that, whenever the user clicks on a specific assignment, they will redirect to the detail page. The detail page will have different information according to what assignment they clicked on. However, I have no idea how to implement this feature.
My home function in Controller/project is as follows
public function home() {
/*if($this->input->cookie('login_status')=='0'){
header("location: Welcome/login");
} else{
*/
$this->load->database();
$this->load->model('scheduler_model');
$this->load->view('header.php');
$data['username'] = $this->input->cookie('username');
$data["getnames"]=$this->scheduler_model->get_users();
$this->load->view('home/homepage',$data);
$data["getassignments"]=$this->scheduler_model->get_assignment();
$data["getselectedcourses"]=$this->scheduler_model->get_select_course();
$this->load->view('home/assignments',$data);
//}
}
My assignment.php in view is as follows:
foreach($getassignments as $getassignment){
if(in_array($getassignment->courseID,$courseArray)){
if($getassignment->due>date("Y-m-d")){
?><a href="detail">
<?php
$assignName='assignment'.$i;
echo $getassignment->name," ",$getassignment->due;
//$this->input->set_cookie('assignName',$getassignment->name,time()+3600);
$assignList =array(
$assignName=>$this->input->set_cookie($assignName,$getassignment->name,time()+3600)
);
?></a>
<?php
echo "<br>";
$i=$i+1;
}
}
}?>
What I am trying to do is that, whenever the user clicks on a specific
assignment, they will redirect to the detail page. The detail page
will have different information according to what assignment they
clicked on. However, I have no idea how to implement this feature. My
home function in Controller/project is as follows
This is how it works!
You will have a method in a controller that list all assignments for your example
function home() {
$data["getassignments"]=$this->scheduler_model->get_assignment();
$this->load->view('home/homepage',$data);
}
You should have a view to listing all those assignments.
foreach($getassignments as $getassignment){
echo "<p><a href = 'controller/details/".$getassignment->id."'>".$getassignment->name."</p>"
}
you should have another method inside a controller to view that selected assignment
function detail($id){
$data["getassignment"]=$this->scheduler_model->get_assignment($id);
$this->load->view('details', $data);
}
Finally, you need a detail view to display the one you need for the selected assignment
I have one header file for the home page and the login page
in that header. I wrote this code on top of it
<?php
if ($this->session->userdata('logged_in')==true ){
redirect('home','refresh');
}else{
redirect('home/login','refresh');
}
?>
but it keeps redirecting me to the same page and it shows nothing
Remove the else redirect on login page, its already in login page
if ($this->session->userdata('logged_in')==true ){
redirect('home');
}
except login, you can redirect the page :)
to differ the login page and home page just send the
$this->data["pagename"]="login"; in login function and
$this->data["pagename"]="home"; in home function
and in header
if ($this->session->userdata('logged_in')==true ){
redirect('home');
} else {
if($pagename!="login")
{
redirect('home/login');
}
}
$user_logged_in=$this->session->userdata('logged_in');
if (!$user_logged_in)
{
redirect('home/login','refresh');
}else{
redirect('home','refresh');
}
<?php
if ($this->session->userdata('logged_in')!==FALSE){
redirect('home','refresh');
}
else{
redirect('home/login','refresh');
}
?>
try the above code..
Try this
put these line in every controller's __construct function
if ($this->session->userdata('logged_in') !=true) {
if ($this->router->fetch_class() != 'home' && $this->router->fetch_method() != "login") {
redirect("home/login");
}
}
I have a site that has a menu for non members and one for members which is shown depending on if the user is logged in or logged out but would like to know how to have an additional menu that is only show to a specific user upon their login by using the user email address to determine that user is shown the third menu.
Thanks in advance
Try this out!
<?php
if (isset($_SESSION['Logged']) && $email == "email#example.com") {
//show the special menu example: admin menu
} else if (isset($_SESSION['Logged'])) {
//show the members menu here
} else {
//show the normal menu code
}
?>
Happy to help!
try this !!!
if ( user logged in )
{
getloggedmenu();
}
else
{
getUnloggedmenu()
}
public function getloogedmenu()
{
return set you menu here;
}
public function getUnloogedmenu()
{ return set you menu here;
}
I want go to the home pages as the privilege of user that current logged in.
When i am trying to open the page that having the link it goes to the home page. What changes that i need on my code
<body>
Home
</body
function home()
{
if($_SESSION['privillage']=="ADMIN")
{
header('location:admin_home.php');
}
elseif($_SESSION['privillage']=='SUPERVISOR')
{
header('location:home.php');
}
else
{
header('location:user_home.php');
}
}
Your function is being used inside an <a href="...">, so it's clearly supposed to return a URL (also you need to echo it)
Your current code is trying to redirect the user immediately, which won't work because you've already sent <a href=".
Try:
function home() {
if($_SESSION['privillage'] == "ADMIN") return "admin_home.php";
if($_SESSION['privillage'] == "SUPERVISOR") return "home.php";
return "user_home.php";
}
header('location is used if you want a PHP script to redirect the browser to another page. What you are trying to do is simply changing the href based on certain conditions.
function home()
{
if($_SESSION['privillage']=="ADMIN")
{
return 'admin_home.php';
}
elseif($_SESSION['privillage']=='SUPERVISOR')
{
return 'home.php';
}
else
{
return 'user_home.php';
}
}
For readability, you could consider using PHP's switch statement
may be you have to capitalize the first letter of "location" use "Location" in header('Location:user_home.php'); :)
i am using opencart in one project,
every thing is working fine but i am unable to find an option to stop view of home page until LOGIN.
actually this is project requirement, no one can see home until LOGIN.
is there way to do this with OPEN CART ?
Thanks
this is untested, but should point you in the right direction:
(OpenCart 1.4.9.x)
Save this to:
catalog/controller/common/check_login.php
<?php
class ControllerCommonCheckLogin extends Controller {
public function index() {
if (!$this->customer->isLogged()) {
// Require to be logged in
$ignore = array(
'account', 'payment'
);
$match = false;
if (isset($this->request->get['route'])) {
foreach ($ignore as $i) {
if (strpos($this->request->get['route'], $i) !== false) {
$match = true;
break;
}
}
}
// Show site if logged in as admin
$this->load->library('user');
$this->registry->set('user', new User($this->registry));
if (!$this->user->isLogged() && !$match) {
return $this->forward('account/login');
}
}
}
}
?>
Edit /index.php
Find:
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance/check'));
Add After:
// Login Check
$controller->addPreAction(new Action('common/check_login'));
Essentially use the same logic as the maintenence check... The big difference is it looks for the word 'account' in the string... If it finds it it allows the page to be displayed, if not it redirects to the login page...
Use the word "account" instead of "login" in case they need to register... All of the account pages already check for loggin so there is no worry there...
Again, untested so you may need to tweak one or two things - but it should/may work by dropping in the code
check_login.php for opencart 1.5.3
<?php
class ControllerCommonCheckLogin extends Controller {
public function index() {
// Require to be logged in
if (!$this->customer->isLogged()) {
// Require to be logged in
$ignore = array(
'account','payment'
);
$match = false;
if (isset($this->request->get['route'])) {
foreach ($ignore as $i) {
if (strpos($this->request->get['route'], $i) !== false) {
$match = true;
break;
}
}
}
// Show site if logged in as admin
$this->load->library('user');
$this->user = new User($this->registry);
if (!$this->user->isLogged() && !$match) {
$this->redirect($this->url->link('account/login'));
}
}
}
}
?>
There is nothing built-in that I know of, but you can do it yourself. Based on your answers to #CarpeNoctumDC's questions you may have to do some digging, but this should get you started:
system/library/customer.php
public function isLogged() { ... }
catalog/controller/common/home.php
if (!$this->customer->isLogged()) {
// login page
exit;
}
The right way to go about this is to open
/catalog/controller/common/home.php
find public function index() { at the top of the code, and after it put
if(!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('common/home');
$this->url->redirect('account/login', '', 'SSL');
}
In case you're unsure how to do this properly, just take a look at the first few lines after public function index() { in
/catalog/controller/account/account.php
setting your code in the home controller to common/home in place of account/account