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
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
Share on other sites

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

if($member)
  do this;
else
  do that;
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.