470,867 Members | 1,793 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,867 developers. It's quick & easy.

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("Location: " . $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?
Jul 17 '05 #1
2 1370
On 19 Jul 2004 09:09:44 -0700, br***@chameleon-systems.com (Bryan)
wrote:
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> 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.


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

include("secure.php");

HTH,

--
David ( @priz.co.uk )

Jul 17 '05 #2
David Mackenzie <me@privacy.net> wrote...

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

include("secure.php");


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
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Albert Ahtenberg | last post: by
52 posts views Thread by Gerard M Foley | last post: by
15 posts views Thread by Taki Jeden | last post: by
2 posts views Thread by Nadav | last post: by
reply views Thread by Dimitrios Mpougas | last post: by
8 posts views Thread by Luciano A. Ferrer | last post: by
13 posts views Thread by souissipro | last post: by
1 post views Thread by comp.lang.php | last post: by
4 posts views Thread by psual | last post: by
13 posts views Thread by Massimo Fabbri | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.