Jump to content


Photo

header problems *SOLVED*


  • Please log in to reply
13 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 21 July 2006 - 07:33 PM

Hey guys,

I'm getting header problems with my script but I can't seem to find the problem... I've read the F.A.Q about headers but it didn't really help me.

I've got index.php that has a login form
that's how I load the pages
<?php
include("includes/cachecontrol.php");
$tmpl=new Template;
$tmpl->errors=0;
$tmpl->cur_page_name="index.php";
include("includes/config.php");

//$tmpl->add_template("top");
include("includes/connect.php");

if ($_COOKIE['remember'] == "" && $_SESSION['remember'] == "") {
	block_check("",$_SERVER['REMOTE_ADDR'],"index.php",$prefix);

    $a = (isset($_GET['a']) ? $_GET['a'] : 'default');
    switch ($a) {
//....
?>

//in cachecontrol.php
<?php

header("Content-Type: text/html; charset=ISO-8859-1");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

//
//	Start the session
//
session_start();

//
//	Build the template class
//
class Template {
var $errors;
var $cur_page_name;

//.....
?>

login2.php  (the part that processes the form)

<?php
ob_start();
include("includes/config.php");
include("includes/connect.php");
$uname=$_POST['uname'];
$pword=$_POST['pword'];
$remember=$_POST['remember'];
$result=mysql_query("SELECT * FROM ".$prefix."users WHERE username='$uname'") or die(query_error());
$result=mysql_fetch_array($result);
$result=$result['password'];
if ($result == "") {
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: error.php?e=1");
}
else {
$active=mysql_query("SELECT * FROM ".$prefix."users WHERE username='$uname'") or die(query_error());
$active=mysql_fetch_array($active);
$active=$active['active'];
  if ($active == "yes") {
    if (md5($pword) == $result) {
    $logged=date('Y-m-d H:i:s');	
	$insert = mysql_query("UPDATE ".$prefix."users SET last_login='$logged' WHERE username='$uname'") or die(query_error());
	header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    session_start();
      if ($remember == "yes") {
      $_SESSION['remember']=$uname;
	  setcookie("remember",$uname,time()+31449600,"/",$site_address);
      }
      else {
      $_SESSION['remember']=$uname;
      }
    header("Location: members.php");
    }
    else {
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Location: error.php?e=2");
    }
  }
  else {
  header("Cache-Control: no-store, no-cache, must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0", false);
  header("Pragma: no-cache");
  header("Location: error.php?e=3");
  }
}
?>

I used ob_start() as a temp solution but I was wondering if there was a better solution

#2 True`Logic

True`Logic
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 21 July 2006 - 07:34 PM

include("./....");  <-- on some servers this gives me problems if u dont include "./", could be it..

#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 21 July 2006 - 07:38 PM

I don't think that's the problem because it worked perfectly before I added an index.php. I just has login.php which had the login form and then would get processed by login2.php and then redirect the user to members.php if the he got approved.

#4 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 21 July 2006 - 09:46 PM

try to put session_start before any header code
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#5 gluck

gluck
  • Members
  • PipPipPip
  • Advanced Member
  • 216 posts

Posted 21 July 2006 - 09:53 PM

I think you are sending an output to the browser before setting the headers. All the headers should be set before any output is sent to the browser
I'm back baby!

#6 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 21 July 2006 - 10:38 PM

ryanlwh, yup that worked perfectly ( I think )

#7 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 21 July 2006 - 11:04 PM

oh got another question, my index.php is for members and non members, to access some of the pages you need to be a member so I did this

<?php
if (isset($_COOKIE['remember']) || isset($_SESSION['remember'])) {
//takes you to the page
} else {
//takes you to the login page
}
?>

my question is, is there a better way of doing this, like just checking at the begining of the page, like checking if the session exists, if it does the username is stored in a variable and if it doesn't exist 'guest' is stored in that variable. I think I answered my own question but I want to see if there's another way of doing it

#8 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 21 July 2006 - 11:07 PM

instead of storing 'member' or 'guest', why not just a true false value?
<?php
if (isset($_COOKIE['remember']) || isset($_SESSION['remember'])) {
  $member  = true;
} else {
  $member = false;
}

if($member)
  do this;
else
  do that;
?>

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#9 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 21 July 2006 - 11:12 PM

see that's why I needed your opinion :P

thanks again ryanlwh

#10 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 21 July 2006 - 11:14 PM

you're welcome. depending on your need, you can even make it even neater
$member = (isset($_COOKIE['remember']) || isset($_SESSION['remember']));

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#11 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 21 July 2006 - 11:22 PM

well $member would contain the username if I do it like that and if they're not logged in $member would be '' so I guess when I need to check if a person is logged in or not I can do if ($member != '')

#12 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 21 July 2006 - 11:24 PM

yeah. it's not a big deal what $member should store or how you check it. just do the best way you think will save you the most headache :)
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#13 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 21 July 2006 - 11:26 PM

my bad, isset returns 1 or 0

#14 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 22 July 2006 - 12:00 AM

1 and 0 basically equals to true or false
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users