I'm using CodeIgniter framework and I need to access the session from 404 error page.
My page is in /application/errors/
I want to the access session to check the user data to take decision.
<?php
if ($this->session->userdata('fUserId') != '') {
include('header.php');
} else {
include('header_without_login.php');
}
?>
I think you should specify session library in autoload.php
There is no special to 404 page
Related
I am new to codeigniter framework. I am trying to build a authentication system.
Authentication is working fine. My problem is that after successfully logging, when I click the back button in the browser it is directed to login page again. I want to redirect it to the home page itself. i want to reload the home page not the index page(index page is the login page, after successful login goes to home page)
How can I do it
In your login page check that login session is started or not, if it is started than redirect to home page :
if(isset($_SESSION['user']))
{
header('Location:http://localhost/projectname/home');
}
If you have any confusion please let me inform.
Thanks
on the home page controller check whether the session exists or not. if it exists then redirect to home page otherwise login page.
In your home_model.php do something like below:
<?php
class Home_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->check_session();
}
function check_session()
{
$session_login = $this->session->userdata("MYLOGIN");
if($session_login == '')
{
redirect('home');
}
if($session_login == 1 && $session_login == TRUE)
{
redirect('home/dashboard');
}
}
}
Load home_model in home controller.
I building a very simple app with Laravel4 and so far i have managed to set up PHPMailer to work with a contact form, the users fill in their details and send me an email, normal stuff, everything works fine.
After the user sent the email successfully, he is redirected to the home page via
if($m->send()) {
header('Location: /path/to/home/');
die();
}
Now what i need is a success message that appears at the top of the homepage if the user has been redirected after a successfully sent email.
I have a div with .success class sitting on top of my home page, absolutely positioned out of view, with a negative Y value.
I tried pulling it down after on $m->send() like so:
if($m->send()) {
header('Location: /path/to/home/');
echo "<script type='text/javascript'>
$('.success').animate({
top: 0
}, 2000);
</script>";
die();
}
but it didnt work. In fact, nothing i echo after the header() has any effect.
What can I do?
Thank you guys!
This is simple HTTP - when you set the Location header, it's telling the browser to leave the page you're on and go somewhere else - anything that happens afterwards (like that little JS snippet) will never reach the browser. You need to put that snippet on the page you're redirecting to, not on this one.
I solved the problem after realizing that you can't use jquery on the document before you actually link the jquery lib in.
So, in my phpmailer config file, I set $_SESSION['success'] = true before i redirect with the header('Location: /path/to/home/'); , and then, on the Homepage, the page I wanted the success message to be displayed on, I added this bit of code (AFTER linking the jQuery library):
<?php
if(isset($_SESSION['success']) && $_SESSION['success'] == true ) {
?>
<script type='text/javascript'> $('.success').animate({top : 0}, 'normal').delay(3000).animate({top : -57}, 'normal');</script>
<?php
} else {
$_SESSION['success'] = false;
}
?>
I don't know if this is a good practice but it does work.
I also had to session_start(); on my Homepage (obviously).
Hope this helps anyone in the same situation!
I am using joomla 2.5.9 version, and I would like Joomla to redirect me to the login page if I am not logged in when i click an article which the Permission Access is for Registered only, but instead Joomla returns me this message: You are not authorised to view this resource.
And I dont see any reason why joomla by default havent made it redirect to login page.
Thanks
This doesn't answer your exact question, but I think it's a good workaround. I'm working on the same issue. My approach at the moment is to check the messages for the "not authorised" string, and then set a flag based on that. You can then check that flag anywhere in template and either redirect, or just choose to optionally show the login form.`
/* get message from app */
$app = JFactory::getApplication();
$messages = $app->getMessageQueue();
/* set login flag to 0 */
$showlogin = 0;
/* if there is a message set... */
if (isset($messages[0])) {
/* loop through messages and check for the "not authorised" string */
foreach ($messages as $msg) {
if ($msg["type"] == "error" && strpos($msg["message"], "not authorised") ) {
/* if found, update login flag */
$showlogin = 1;
}
}
}
/* include in template body - you could redirect here instead of including login form */
if ($showlogin) { ?>
<jdoc:include type="modules" name="login-form" style="none" />
<?php } ?>
`
this happens when you try to access an article which is not visible, but the category is publically visible.
Seems like it is not considered a bug, but I think its a pretty unexpected "feature".
To fix this you can edit:
joomla/components/com_content/views/article/view.html.php
// Check the view access to the article (the model has already computed the values).
if ($item->params->get('access-view') == false && ($item->params->get('show_noauth', '0') == '0'))
{
$app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error');
$uri = urlencode(base64_encode(JURI::getInstance()->toString()));
JFactory::getApplication()->redirect(
JRoute::_('index.php?option=com_users&view=login&return='. $uri, false)
);
return;
}
This will show the login screen and return to the article after a succesfull login.
If you dont want to edit the core file (because you want to update your system), you have to create a system plugin to override this.
I done project in ASP.net MVC3. In my project i create a session as follows in Home Controller
if (Session["ulclass"] == null)
{
Session["ulclass"] = "list";
}
I use this session to my Product List page.. as a class for div tag as follows..
<div id="listheading" class="listHead" #if (Session["ulclass"].ToString() == "grid")
{
<text>style = "display:none;";</text>
}>
When i copy this Productlist URL from FireFox to Chrome...
session value not come.. it produce the error...
Can any one help this ?
You can use cookieless sessions. That way the session id is sent in the URL instead of a cookie, so then you could just copy the URL anywhere and you are still in the same session.
Put this in web.config:
<sessionState cookieless="true" />
(The drawback is of course that anyone can copy the URL anywhere and still be in your session...)
More about cookieless session: http://msdn.microsoft.com/en-us/library/aa479314.aspx
Use Convert.ToString(Session["ulclass"]) == "grid" to avoid error first, and then add in we.config
Magento Session in external page (same domain) is not working well, I've checked all the other topics here but any solution it is working.
require_once ( "../app/Mage.php" );
umask(0);
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
if($session->isLoggedIn()){
//do it
} else {
// Transfer them to a login page
header("Location: http://www.mydomain.com/customer/account/login/");
}
I can not get this to work, I have checked all recommendations everywhere and nothing work.
Just for your information, after the header() function, there should be another line:
exit;
for the redirection to work.
(Apparently this belongs more to a comment rather than an answer, but I don't have the privilege to comment everwhere yet.)
You can try these lines instead, they looks similar, but work for me on Magento 1.5.1..
require_once ( "../app/Mage.php" );
umask(0);
Mage::app("default");
if(Mage::getSingleton('customer/session')->isLoggedIn()){
//do it
}
else {
// Transfer them to a login page
header("Location: http://www.mydomain.com/customer/account/login/");
}
I think your issue is that you already have a session started, so your attempts to start a magento session and get data from it are failing.
If you look inside Mage_Core_Model_Session_Abstract_Varien, the first thing it does is look to see if the $_SESSION variable is already set and return if it is. You could set your debugger breakpoint there and verify if you aren't sure.
You could close the other session and start the magento session to get your data, or you could get both to share the same session