CodeIgniter redirect not working? - php

Ok I have a controller named Login and have an index() function that displays the view user/login. I build the urls with user/login, but with the redirect, I'm doing this:
redirect('/user/login/');
But I've also tried redirect('/login/');
How comes my login won't load? It keeps giving me a 404 error...
I've also tried ('/login/index') and ('/login')

It sounds like you have only one controller, Login, with only one page, index, in it, so why do you need a redirect? Are you just trying to get your index page to show your login view? If so you do that with something like:
$this->load->view('path/to/view');

you can try redirect(site_url("login"));, if you haven't changed the relevant routing in your CI install it will take you to the login controller (and the index() method by default)
edit: I misread the question

Ah.. sorry, my bad. I have an if statement that isn't even letting it get to the redirect part... I'm sorry!

Related

http0.0000000.000000www .. On Wordpress Log Out Redirect

I try to create a logout link which redirect to home url. I've tried this function:
wp_logout_url(site_url)
but, the output resulting strange prefix.
http://example.com/wp-login.php?action=logout&redirect_to=http0.0000000.000000www.example.com&_wpnonce=f2c0bef0b0
then I trying to hardcode the site_url(), but that prefix still exist and redirecting to wrong url.
How to solve it?
Thanks,
Wildan
I need to put urldecode() function. don't know why. So, it'll look like:
urldecode(wp_logout_url(site_url))

Session redirect to home when id is null with codeigniter 3.0

Here is my code in controller:
$newdata = array(
'uid' => $usern,
'ou' => $filter
);
$this->session->set_userdata($newdata);
$this->masterpage->view('User/homeuser');
And here is my code in views:
<?php
$user = $this->session->all_userdata();
if ($this->session->userdata('uid')=='') {
redirect('main/main', 'refresh');
}
?>
However when I type link: http://localhost/[system_name]/index.php/[controller_name]/index
(link to show when uid is null, the page should redirect to main)
Only blank page is appearing. It seems it didn't redirect to the main/main page. Can anyone help me ? Thanks.
You can not do redirect in views. Use controllers for this, so move your logic to check session data from view to the controller.
View is rendered at the very end of your request so if there is some output, php will not redirect you to anywhere. You see blank page probably because you turned off errors display, but I am sure if you check php error log you'll see there is an error "can not modify headers" or so.
If you deadly want to do redirect in views, use Javascript for that.
This is the most silly things I've done. I just forget to import session from library. So should in my public function I put this function.
$this->load->library('session');
This is what happen when you try to built two system simultaneously. Anyway thanks for the response and tried to solve it for me.

laravel redirection to splash page during testing

I've spent too many hours messing with this
I'm just starting with laravel and started a new project.
I want to be able to have a system where a certain users can access the site while it is in development. The rest of the public gets forwarded to the splash page.
I plan to create a secret route that sets a toggle in the session. If this toggle is set then the user can use the entire system. Else they are redirected to the splash page.
The issue is I cannot get it to redirect. I have been adding the code in the bootstrap->start.php file. The standard
header('location:www.thesite.com')
starts doing funny things that I do not understand.
If I run
return Redirect::to(htmlspecialchars_decode($url))
it returns the error:
BadMethodCallException
Method [run] does not exist on Redirect.
I have absolutely no idea what is going on or how to fix it.
Why is the redirection script returning an error? Is start.php not the correct location?
If so how can achieve my objective within laravel?
You should do this in your before filter in app/filters.php like so:
App::before(function($request){
if(!$request->is('splash') && Input::get('allow') != '1')
{
return Redirect::to('/splash');
}
);
Where /splash is your splash screen route. You can then do http://www.example.com?allow=1 to bypass the splash screen.
The before filter is a function that is run before every single route in your application.
Let me know if this works for you!

php redirect() not working on online server

I had redirected my page like:
redirect(base_url().'user/login/?redirect=site/cart_steps/steps');
and it works fine in localhost and when i uploaded it to server it didnt redirect. I checked all the codes and above this all code executes. But when it comes to redirect the page doesnt redirects. I also tried
redirect(base_url().'user/login?redirect=site/cart_steps/steps');
redirect(base_url().'user/login');
header('Location:'.base_url().'user/login?redirect=site/cart_steps/steps');
header('Location:'.base_url().'user/login');
but the page didn't redirect? and also i checked out this The header function is not working on online server?
but it cant help me too.... can any one explain what is the problem here....
You can use the refresh method like this:
<?php
redirect($this->input->server('HTTP_REFERER'), 'refresh'); // refresh the page
?>
Another common mistake could be echoing out / printing something before the redirection.
I would check your CodeIgniter error logs to verify that particular file isn't throwing any error messages that could tell you what needs fixing.
If you haven't already, you'll probably also want to make sure that the URL helper is loaded.
ex:
$this->load->helper('url');
Another solution
<meta http-equiv="refresh" url=http://example.com/">
Try to use like this,
First define your base URL as :
$base_url = "Your base url";
then apply this $base_url variable to your redirect link.
Hope this will help.

Need help with Code Igniter [did not found page created]

so I hope someone would help me.
My first page is leave_app.php. In this page I put a link to apply leave, using the normal code:
New Leave Application
However the link didn't display as I had wished for.
"The requested URL /ci/add.php was not found on this server." and the link in the browser leads to this "http://localhost/ci/add.php".
I don't know why the server didn't find the page. I already made add.php page, also add at the leave_app controller the function add().
In the config.php file I put $config['index_page'] = '';
I have asked around but no one can help. I have already surfed around, but still don't know how to solve.
The beauty of Codeigniter is to rewrite urls in a clean manner, so all things go through index.php and the corresponding controller is loaded
Try accessing it like so:
/ci/index.php/add
Make sure your controller is in application\controllers\add.php and named Class Add

Categories