...

View Full Version : quick question..



DiarYofaMadmaN
05-03-2004, 05:27 AM
This is not working like I would like it too but I'm thinking it's not possible to do it this way... am I right?

<html>
<head>
<title>
</title>
</head>
<body>

<?
session_start();
if (($_SESSION['userstatus'] != 'admin')) {
header ("Location: /login.php");
}
?>
</body>
</html>

Steveo31
05-03-2004, 06:24 AM
session_start has to go on the VERY FIRST LINE. That includes before DOCTYPE and all.

session_start();
<html>
<head>
<title>
</title>
</head>
<body>

<?
if (($_SESSION['userstatus'] != 'admin')) {
header ("Location: /login.php");
}
?>

</body>
</html>

firepages
05-03-2004, 07:19 AM
Also please keep your thread titles as decriptive as possible 'quick question' is bad juju :eek:

raf
05-03-2004, 11:46 AM
2 problems with Steveo31 post:
- the session_start() should be enclosed with PHP tags
- the redirect also needs to be placed before any output is sent to the client.

So your code would be


<?php
session_start();
if ($_SESSION['userstatus'] != 'admin') {
header ("Location: /login.php");
die();
}
?>
<html>
<head>
<title>
</title>
</head>
<body>
</body>
</html>


(so also don't use shorttags and place a die() after the redirect, just to e safe)

DiarYofaMadmaN
05-03-2004, 05:50 PM
2 problems with Steveo31 post:
- the session_start() should be enclosed with PHP tags
- the redirect also needs to be placed before any output is sent to the client.

So your code would be


<?php
session_start();
if ($_SESSION['userstatus'] != 'admin') {
header ("Location: /login.php");
die();
}
?>
<html>
<head>
<title>
</title>
</head>
<body>
</body>
</html>


(so also don't use shorttags and place a die() after the redirect, just to e safe)

I've read that some browsers don't really like: header ("Location: "); so i tried this:
header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php"); I keep getting: No input file specified. printed out on the page.. I have no clue why but i'm getting further then i did before...

$_SERVER['HTTP_HOST'] should be pointing to www.maxforcepc.com/ and $_SERVER['PHP_SELF'] should be pointing to edit/ because that's where the script is located...

Well, the header is working but it's forwarding the page to: http://www.maxforcepc.com/login.php instead of edit/login.php
-Thanks,
Rich

DiarYofaMadmaN
05-03-2004, 07:02 PM
nvm i fixed it i just had to use index.php instead of /index.php it was pointing to the wrong directory...

-peace

DiarYofaMadmaN
05-03-2004, 08:29 PM
Scratch what i said cause it's not working

i'm using:


header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."index.php");

which I think should be forwarding to edit/index.php if my syntax is correct but it's not forwarding. It's forwarding to http://www.maxforcepc.com/editindex.php instead of edit/index.php. I tried putting a / infront of index.php but it's still coming back as editindex.php. I have no clue can someone help me with this problem? I'm sry to be bugging you guys but i'm getting really far with this and I'v been coding stuff on my own just can't figure out this problem even though i'm reading the php manual. I'm not trying to have you guys write the code for me...

-peace

raf
05-03-2004, 08:37 PM
Just use


header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/index.php');

Should work perfectly. If the / doesn't show, then make sure you saved the file, make sure you don't load a buffered file etc



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum