Jump to content

header problems *SOLVED*


digitalgod

Recommended Posts

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
[code]
<?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;

//.....
?>
[/code]

login2.php  (the part that processes the form)

[code]
<?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");
  }
}
?>
[/code]

I used ob_start() as a temp solution but I was wondering if there was a better solution
Link to comment
https://forums.phpfreaks.com/topic/15288-header-problems-solved/
Share on other sites

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

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

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
Link to comment
https://forums.phpfreaks.com/topic/15288-header-problems-solved/#findComment-61878
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.