There is "Logout" link all over the site. If we click on Logout, it will redirect to this page.
http://sitename/customer/account/logoutSuccess/
but in some phtml pages for example , in below page
http://sitename.com/marketplace/marketplaceaccount/myproductslist/
if we click on "Logout", it should logout but redirect to following url :
http://sitename.com/marketplace.
In google i found redirecting for entire site. but i need only for some pages.
I am using following code : Accountcontroller.php
require_once 'Mage/Customer/controllers/AccountController.php';
class Webkul_Marketplace_AccountController extends Mage_Customer_AccountController{
public function marketlogoutAction()
{
$this->_getSession()->logout()
->renewSession();
//add your code here
$this->_redirect('marketplace');
echo "something";
exit();
}
public function logoutAction()
{
$this->_getSession()->logout()
->renewSession();
$this->_redirect('*/*/logoutSuccess');
}
Data.php [app/code/local/Mage/Customer/Helper ]
public function getLogoutUrl()
{
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
if (strpos($currentUrl,'marketplaceaccount') !== false) {
return $this->_getUrl('marketplace');
}else
{
return $this->_getUrl('customer/account/logout');
}
}
but when i log out from some phtml pages, its redirecting to the page that i required, but its not logged out.
Change your helper (Data.php) function to:
return $this->_getUrl('customer/account/marketlogout');
instead of
$this->_getUrl('marketplace')
Otherwise it's just redirect you to the marketplace url
use this code..
data.php
public function getLogoutUrl()
{
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
if (strpos($currentUrl,'marketplaceaccount') !== false) {
return $this->_getUrl('marketplace/account/marketlogout');
} else if (strpos($currentUrl,'mpshippingmanager') !== false) {
return $this->_getUrl('marketplace/account/mpshippingmanagerlogout');
} else if (strpos($currentUrl,'mpmassuploadaddons') !== false) {
return $this->_getUrl('marketplace/account/mpmassuploadaddonslogout');
}else if (strpos($currentUrl,'mpassignproduct') !== false) {
return $this->_getUrl('marketplace/account/mpassignproductlogout');
}else
{
return $this->_getUrl('customer/account/logout');
}
}
this is for action. add one function in Accountcontroller
public function mpmassuploadaddonslogoutAction()
{
Mage::getSingleton('customer/session')->logout();
//add your code here
$this->_redirect('mpmassuploadaddons');
}
public function mpmassuploadaddonslogoutAction()
{
Mage::getSingleton('customer/session')->logout();
//add your code here
$this->_redirect('mpmassuploadaddons');
}
public function mpassignproductlogoutAction()
{
Mage::getSingleton('customer/session')->logout();
//add your code here
$this->_redirect('mpassignproduct');
} public function marketlogoutAction()
{
Mage::getSingleton('customer/session')->logout();
//add your code here
$this->_redirect('marketplace');
}
Related
Under htdocs folder i have created folder called PHP under that i have created file called index.php. I have written wrouting PHP code but it is not working.
index.php
<?php
echo "Welcome" . "<br>";
$routes = [];
route('/', function () {
echo "Home Page";
});
route('/login', function () {
echo "Login Page";
});
route('/about-us', function () {
echo "About Us";
});
route('/404', function () {
echo "Page not found";
});
function route(string $path, callable $callback) {
global $routes;
$routes[$path] = $callback;
}
run();
function run() {
global $routes;
$uri = $_SERVER['REQUEST_URI'];
$found = false;
foreach ($routes as $path => $callback) {
if ($path !== $uri) continue;
$found = true;
$callback();
}
if (!$found) {
$notFoundCallback = $routes['/404'];
$notFoundCallback();
}
}
http://localhost/PHP/
Welcome
Page not found
http://localhost/PHP/index.php/login/ (getting below output)
Welcome
Page not found
Expected output
Welcome
Login Page
Here wt am doing mistake, can anyone explain and update my code
I'm trying to conditionally load my front-end and admin area code in WordPress plugin, so the file and class that creates admin area will on load on admin side and file and class that is needed to be run on front-end will run only on front-end and won't touch anything on admin area.
I tried to use is_admin() conditional:
if (!is_admin()) {
require_once(plugin_dir_path(dirname(__FILE__)) . 'public/class-public.php');
$this->Public = new Public();
} else {
require_once(plugin_dir_path(dirname(__FILE__)) . 'admin/class-admin.php');
$this->Admin = new Admin();
}
code loading was fine, but AJAX was not working on public side, as AJAX requests bound to either wp_ajax_ or wp_ajax_nopriv_ actions are executed in the WP Admin context. So I decided to create my own isAdmin() function:
public static function isAdmin() {
$currentUrl = set_url_scheme(
sprintf(
'http://%s%s',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
)
);
$adminUrl = strtolower(admin_url());
$referrer = strtolower(wp_get_referer());
if (strpos($currentUrl, $adminUrl) === 0) {
if (strpos($referrer, $adminUrl) === 0) {
return true;
} else {
if (function_exists('wp_doing_ajax')) {
return !wp_doing_ajax();
} else {
return !(defined('DOING_AJAX') && DOING_AJAX);
}
}
} else {
if (!defined('REST_REQUEST') || !REST_REQUEST) {
return false;
}
return (isset($_REQUEST['context']) && $_REQUEST['context'] === 'edit');
}
}
code loading was still fine, but now AJAX was working on the public side and not working on the admin side.
So, how can I prevent loading public code on admin area code and vice versa with AJAX working on both sides?
I managed to resolve this issue by also checking for public interface. I created new function isPublic() to check if it is public. So here is my final code:
if ($this->isPublic()) {
require_once(plugin_dir_path(dirname(__FILE__)) . 'public/class-public.php');
$this->Public = new Public();
} elseif ($this->isAdmin()) {
require_once(plugin_dir_path(dirname(__FILE__)) . 'admin/class-admin.php');
$this->Admin = new Admin();
}
and here are helper isPublic() and isAdmin() functions:
public static function isAdmin() {
if (function_exists('is_admin') && is_admin()) {
return true;
} else {
if (strpos($_SERVER['REQUEST_URI'], 'wp-admin') !== false) {
return true;
} else {
return false;
}
}
}
public static function isPublic() {
if (function_exists('is_admin') && is_admin()) {
if (function_exists('wp_doing_ajax') && wp_doing_ajax()) {
return true;
} else {
return false;
}
} else {
if (strpos($_SERVER['REQUEST_URI'], 'wp-admin') !== false) {
if (strpos($_SERVER['REQUEST_URI'], 'admin-ajax.php') !== false) {
return true;
} else {
return false;
}
} else {
return true;
}
}
}
how do i pass TRUE / FALSE after update done and redirect to Index() and set
condition $viewdata['show'] to append my html sucess or something
My Controller
class Description extends CI_Controller {
public function index()
{
$viewdata['content']=$this->General_model->get_page_uri();
$viewdata['show']=; //where i want to get value when update() method
//pass value so i can show sucess / error message
$this->load->view("backend/content_view",$viewdata);
}
public function update()
{
$title=$this->input->post('txttitle');
if($title != '')
{
if(!$this->update_model->update_all($title))
{
return FALSE;
}
return TRUE;
}
redirect('Admin/Description');
}
}
My Model
public function update_all($data)
{
$this->db->set('desc',$data)
->where('desc_id','1');
if(!$this->db->update('tbl_desc'))
{
return FALSE;
}
return TRUE;
}
#Ritesh d joshi thz it work but i face problem that i can't modify when update error i test to change my field name to other to test return false;
Admin/Description/update
it show me 'A Database Error Occurred' by Codeigniter
i don't want this to show i want to keep my Admin page still same just alert nomol message error that i have set not to show many info error. how could i prevent this or this can be done by Ajax request only ?
Controller index()
if($show_ses === '0')
{
$viewdata_result = $this->General_model->rk_alert_ok('Successfully Update');
$this->session->set_flashdata('show', 'false');
}elseif($show_ses === '1'){
$viewdata_result=$this->General_model->rk_alert_no('Fail Update Request');
$this->session->set_flashdata('show', '');
}
Controller update()
if(!$this->update_model->update_all($title))
{
$this->session->set_flashdata('show', '1');
//1= false
}else{
$this->session->set_flashdata('show', '0');
//0=true
}
Use the PHP header() function.
header('Location: your_URL');
Update:
In CI, you can use redirect() function, this document will help you to understand: http://www.codeigniter.com/user_guide/helpers/url_helper.html
Please try this
class Description extends CI_Controller {
public function index()
{
$viewdata['content']=$this->General_model->get_page_uri();
$show= $this->session->flashdata('show');
if($show){
// Here is code for show and message
$viewdata['show']="message";
$this->session->set_flashdata('show', 'false');
}
$this->load->view("backend/content_view",$viewdata);
}
public function update()
{
$title=$this->input->post('txttitle');
if($title != '')
{
if(!$this->update_model->update_all($title))
{
return FALSE;
}
$this->session->set_flashdata('show', 'true');
return TRUE;
}
redirect('Admin/Description');
}
}
You can use redirection in update() as:
public function update()
{
$title = $this->input->post('txttitle');
if($title != '')
{
$status = $this->update_model->update_all($title);
if($status){
redirect(base_url().'index?show=1');
}
else{
redirect(base_url().'index?show=0');
}
}
redirect('Admin/Description');
}
than you can check the status in index() as:
public function index()
{
$viewdata['content']=$this->General_model->get_page_uri();
if(isset($this->input->post('show')) && intval($this->input->post('show')) == 0){
$viewdata['show'] = 1; // if success than show 1
}
else{
$viewdata['show'] = 0; // if error than show 0
}
$this->load->view("backend/content_view",$viewdata);
}
You can use the Header function, and to detect it you can pass the parameters too in the GET Url like below.
By default set the status as FALSE. ANd you can update the status according to your conditions either to FALSE or TRUE.
public function update()
{
$status = false;
$title=$this->input->post('txttitle');
if($title != '')
{
if(!$this->update_model->update_all($title))
{
$status = FALSE;
return FALSE;
}
$this->session->set_flashdata('show', 'true');
$status = TRUE;
return TRUE;
}
header('Location: abc.php?status='.$status);
}
Hope This will work, Do let me know in case of any confusion.
Laravel is not redirecting to an returned external url.
public function main ($status,$projectid,$respid,$country) {
//Store the passed-in URL parameters to private properties
$this->status = $status;
$this->projectid = $projectid;
$this->respid = $respid;
$this->country = $country;
//Run the starting function
if ($this->verifyId()) {
$this->getLinks();
$this->storeData();
$this->prjUpdate();
$this->redirect();
}
}
public function redirect () {
//Redirect to the set redirect links
if ($this->status === "Complete")
{
return redirect()->away('http://google.com', 302);
} elseif ($this->status === "Incomplete")
{
return redirect()->away('http://google.com');
} elseif ($this->status === "Quotafull")
{
return redirect()->away('http://google.com');
}
}
The $this->redirect() is not redirecting to the set URL return redirect()->away('http://google.com', 302); but when I do var_dump($this->redirect()); it works. If var_dump() is removed it doesn't redirect.
Try to replace
//Run the starting function
if ($this->verifyId()) {
$this->getLinks();
$this->storeData();
$this->prjUpdate();
$this->redirect();
}
with
//Run the starting function
if ($this->verifyId()) {
$this->getLinks();
$this->storeData();
$this->prjUpdate();
return $this->redirect();
}
Here's what I'm trying to do. This is the function in the controller
public function get_started()
{
if(test_login($this->session->all_userdata())) {
$this->load->view('template');
} else {
$this->load->view('error');
}
}
This is the helper
function test_login($sessdata)
{
if($sessdata->userdata('is_logged_in')) {
return true;
} else {
return false;
}
}
I have entered is_logged_in as a boolean session variable.
However, this doesn't work.
I can't find the error.
instead of passing session data as parameter to your helper, you could access the session from helper itself, like:
function test_login() {
$CI = & get_instance(); //get instance, access the CI superobject
$isLoggedIn = $CI->session->userdata('is_logged_in');
if( $isLoggedIn ) {
return TRUE;
}
return FALSE;
}
And controller:
public function get_started(){
if( test_login() ) {
$this->load->view('template');
}
else {
$this->load->view('error');
}
}