PHP Catastrophe! header() hates me.
Moderator: General Moderators
PHP Catastrophe! header() hates me.
...it rhymes, it can't be good!
My lovely site was/is working fine on my computer. However, I upload it to the server space someone was kind enough to buy for me, and it goes to hell. Basically, my redirection with header() stopped working. It's not that the header() function doesn't work, it's that I seem to not be able to have ANY code above of it.
Now I know I know, you are going to say, "yes, it says you can't do that in the manual", but I mean php code. Like a test to whether it should do it or not.
My phpinfo()
Their phpinfo()
Mostly, I'm just including the code code before my header() redirects, but I'm not outputting anything first, which should (to my knowledge) not effects the outcome then, because I didn't start the page yet.
Basically, I need help bad, I'll give you any code you want to look at, just let me know.
Edit: I'm not using absolute URL's, as in header("Location: ../login.php"), but I tried the full URL and it also didn't work. Plus the partial also worked on my computer.
I'm using sessions if that matters. I tried closing them first, but it didn't help.
My lovely site was/is working fine on my computer. However, I upload it to the server space someone was kind enough to buy for me, and it goes to hell. Basically, my redirection with header() stopped working. It's not that the header() function doesn't work, it's that I seem to not be able to have ANY code above of it.
Now I know I know, you are going to say, "yes, it says you can't do that in the manual", but I mean php code. Like a test to whether it should do it or not.
My phpinfo()
Their phpinfo()
Mostly, I'm just including the code code before my header() redirects, but I'm not outputting anything first, which should (to my knowledge) not effects the outcome then, because I didn't start the page yet.
Basically, I need help bad, I'll give you any code you want to look at, just let me know.
Edit: I'm not using absolute URL's, as in header("Location: ../login.php"), but I tried the full URL and it also didn't work. Plus the partial also worked on my computer.
I'm using sessions if that matters. I tried closing them first, but it didn't help.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
I use header() all over the place, so here is an example of when it fails trying to log in...
I send the username (uid) and password (pwd) to login.php:
As you can see that includes a file with the function to check my passwords:
That, finally includes the functions I use to connect to my database:
That is the code as it was, working on my computer (OS X, with the entropy.ch PHP whatever). As you can see I still have a descent amount of test code still in

It seems so simple when I do it in my pages, but when I have to put it all together like that to show what it has to do, seems kinda complicated.
I send the username (uid) and password (pwd) to login.php:
Code: Select all
<?php
require_once("CheckLP.php");
if(session_id() == NULL)
{
session_start();
}
?>
<?php
$error = false;
$uiderror = 0;
$pwderror = 0;
if(!isset($_POST['uid']) || isset($_POST['uid']) == "")
{
//die("uid");
$uiderror = 1;
$error = true;
}
if(!isset($_POST['pwd']) || isset($_POST['pwd']) == "")
{
$pwderror = 1;
$error = true;
}
if($error == true)
{
$referer = $_SERVER['HTTP_REFERER'];
header("Location: ../login.php");
//die("before");
exit;
//die("after");
}
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
if(CheckLP($uid, $pwd))
{
session_register('uid');
$_SESSION['uid'] = $uid;
session_register('logged');
$_SESSION['logged'] = true;
session_register('uid');
$_SESSION['uid'] = $uid;
session_register('style');
$userdata = GetData("users", "style", "uid", $uid);
if($userdata != NULL)
{
$_SESSION['style'] = $userdata[0];
}
else
{
$_SESSION['style'] = "blue";
}
session_unregister('lperror');
header("Location: ../logged.php");
exit;
}
else
{
//die("dead");
session_register('logged');
$_SESSION['logged'] = false;
session_register('lperror');
$_SESSION['lperror'] = true;
}
$referer = $_SERVER['HTTP_REFERER'];
header("Location: ../login.php");
exit;
?>Code: Select all
<?php include("../insert/intouchdb.html"); ?>
<?php
function CheckLP($uid, $pwd)
{
$userdata = GetData("users", "pwd", "uid", $uid);
$pwdmd5 = md5($pwd);
if($userdata[0] != NULL && $pwdmd5 == $userdata[0])
{
return true;
}
else
{
return false;
}
}
?>Code: Select all
<?php
#########################
## Prerequisite for DB ##
## ######################
require_once('DB.php');
global $db;
$db = DB::connect("mysql://dbo107486618:qfpWZ6jt@db108.perfora.net/db107486618");
if(DB::isError($db))
{
//die("isError1");
die($db->getMessage());
}
//Return An Array of data in
function GetData($table, $querydata, $whereitem = NULL, $wherevalue = NULL, $sortby = NULL)
{
//die(var_dump($where));
$db = &$GLOBALS['db'];
$sql = "SELECT {$querydata} FROM {$table}";
if($whereitem != NULL && $wherevalue != NULL)
{
$where = " WHERE $whereitem="$wherevalue"";
$sql = $sql.$where;
//die(var_dump($sql));
}
if($sortby != NULL)
{
$sortby = " ORDER BY $sortby";
$sql = $sql.$sortby;
//die(var_dump($sql));
}
//die(var_dump($sql));
$query = $db->query($sql);
if(DB::isError($query))
{
die($query->getMessage());
}
while($query->fetchInto($row))
{
foreach($row as $data)
{
$dbdata[] = $data;
}
}
if(isset($dbdata) && $dbdata != NULL)
{
return $dbdata;
}
}
function InsertData($table, $columns, $values)
{
$count = count($columns);
$cols = "$columns[0]";
$vals = ""$values[0]"";
for($x = 1; $x < $count; $x++)
{
$cols = "{$cols}, {$columns[$x]}";
$vals = "{$vals}, "{$values[$x]}"";
}
$sql = "INSERT INTO {$table} ({$cols}) VALUES ({$vals})";
//die($sql);
$db = &$GLOBALS['db'];
$query = $db->query($sql);
if(DB::isError($query))
{
die($query->getMessage());
}
$referer = $_SERVER['HTTP_REFERER'];
header("Location: {$referer}");
}
function UpdateData($table, $column, $value, $whereitem = NULL, $symbol = NULL, $wherevalue = NULL, $string = NULL)
{
if($string == true)
{
$quote = """;
}
$sql = "UPDATE {$table} SET {$column}={$quote}{$value}{$quote} WHERE {$whereitem}{$symbol}"{$wherevalue}"";
//var_dump($sql);
$db = &$GLOBALS['db'];
$query = $db->query($sql);
if(DB::isError($query))
{
die($query->getMessage());
}
return $sql;
}
?>It seems so simple when I do it in my pages, but when I have to put it all together like that to show what it has to do, seems kinda complicated.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
{
session_start();
}
?>
<?php
$error = false;
$uiderror = 0;(remove the jumping in and out of php)
Sorry...what would be the problem?
Does jumping in and out make possible errors or what?
The problem I seem to be having is that it just ignores the header(), gets to the exit and of course stops.
Does jumping in and out make possible errors or what?
The problem I seem to be having is that it just ignores the header(), gets to the exit and of course stops.
Last edited by ast3r3x on Thu Aug 19, 2004 9:20 pm, edited 1 time in total.
I guess my next question I'll try to stick in this thread...
When I login, I start and make the session variables I need. I have them, and checked before I used header() to go to the next page that tells me I have logged in. When I get to that page, my session information no longer exists. What happened?
When I login, I start and make the session variables I need. I have them, and checked before I used header() to go to the next page that tells me I have logged in. When I get to that page, my session information no longer exists. What happened?