Redirection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bryan

    Redirection

    I'm trying to use redirection to secure certain pages on my site. The
    theory is to check to see if a user is "logged in" at the top of a
    page, and if not, redirect them to a login page.

    A typical web page will look like this:

    <!--#include virtual="secure .php"-->
    <html>
    <body>
    <p>Secure Content Here</p>
    </body>
    </html>

    The secure.php file looks like this:

    <?
    session_start() ;

    $schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';

    // Check to see if the user is logged in.
    if (! isset($_SESSION["userid"]))
    {
    header("Locatio n: " . $schema .
    exit();
    }

    ?>

    This all works fine in ASP. In PHP, however, I can't seem to get the
    redirect to work. If I just type the secure.php URL directly into the
    browser's address bar, it will redirect properly. If I call the page
    I want to secure (either with a .html or a .php extension), it just
    seems to ignore the redirect.

    Any idea why?
  • David Mackenzie

    #2
    Re: Redirection

    On 19 Jul 2004 09:09:44 -0700, bryan@chameleon-systems.com (Bryan)
    wrote:
    [color=blue]
    >I'm trying to use redirection to secure certain pages on my site. The
    >theory is to check to see if a user is "logged in" at the top of a
    >page, and if not, redirect them to a login page.
    >
    >A typical web page will look like this:
    >
    ><!--#include virtual="secure .php"-->
    ><html>
    > <body>
    > <p>Secure Content Here</p>
    > </body>
    ></html>[/color]
    [color=blue]
    >This all works fine in ASP. In PHP, however, I can't seem to get the
    >redirect to work. If I just type the secure.php URL directly into the
    >browser's address bar, it will redirect properly. If I call the page
    >I want to secure (either with a .html or a .php extension), it just
    >seems to ignore the redirect.[/color]

    If the page you want to secure is a .php, you need only use:

    include("secure .php");

    HTH,

    --
    David ( @priz.co.uk )

    Comment

    • Bryan

      #3
      Re: Redirection

      David Mackenzie <me@privacy.net > wrote...[color=blue]
      >
      > If the page you want to secure is a .php, you need only use:
      >
      > include("secure .php");[/color]

      That was the issue. It was a .html page, not a .php page. ASP (or
      more accurately, IIS) will allow you to do this, but apparently PHP
      and/or Apache won't.

      I ended up figuring out exactly what you suggested, and it worked.

      Thanks for the response.

      Bryan

      Comment

      Working...