Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:49:50+00:00 2026-06-13T02:49:50+00:00

If I ignore the 302, I see that redirect() stops output, but header() doesn’t.

  • 0

If I ignore the 302, I see that redirect() stops output, but header() doesn’t. redirect() uses header() to set the 302 response. Different behaviour, same function. What gives?

Some context: I’m building a site with CodeIgniter, and I’m playing with how the site should deal with guests and members.

Extending the CI Core:

class MY_Controller extends CI_Controller {
    if (! $authenticated) redirect('/login');
}

Now a controller:

class Members_only extends MY_Controller {
    function index()
    {
    // Display members only content
    }
}

Then I thought, what if Alice (an unauthenticated visitor) ignores the 302 response? Can she see the rest of the content after the redirect? So I tested it, and now I’m totally confused. There’s two functions that are available to me to send a 302 redirect.

header('Location: http://mywebsite.com/login', TRUE, 302);

And from CI’s URL helper:

redirect('/login');

Here is what it looks like from the inside:

function redirect($uri = '', $method = 'location', $http_response_code = 302)
{
    if ( ! preg_match('#^https?://#i', $uri))
    {
        $uri = site_url($uri);
    }

    switch($method)
    {
        case 'refresh' : header("Refresh:0;url=".$uri);
                         break;
        default        : header("Location: ".$uri, TRUE, $http_response_code);
                         break;
    }
    exit;
}

site_url() is returning “http://mywebsite.com/login”.

Can someone point out what I’m missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:49:52+00:00Added an answer on June 13, 2026 at 2:49 am

    Do you see the exit in the CI redirect function? So whenever you use it, it will cause your application to stop processing whatever code you have left. This is the “different” behavior your are experiencing.

    http://php.net/manual/en/function.exit.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know Hg's ignore is useful, but is there a way that I can
I am trying to ignore the enter key, but i do not want to
I want to ignore all the UserWarning in my dev environment so that they
The Situation (Ignore this it is boring): I have reports that I created using
Edit: Ignore this, I figured it out about 3 seconds after posting this but
What search do when they found different status code? 302 301 404 etc... I
Ignore for the moment that not all browsers support LocalStorage. Would it be possible
How to ignore commas in between double quotes and remove commas that are not
How do I ignore everything in a bin folder which is inside different projects?
why ignore my second WHERE function? With this function I get all news but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.