configuration file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

configuration file

Post by Nay »

i want to include my config.php which has all the variables in it.

i've tried require() and include(). but i get header errors when i try to use them (actions.php):

Code: Select all

<?
session_start();

if ($username == "") {
header("Location: index.html"); }

else {

require("config.php");

$id = $_GET['id'];

if ($id == "login")
	{
		$username = $_POST['username'];
		$password = $_POST['password'];
		$password = md5($password);

		$c = mysql_connect("$host", "$user", "$pass");
		$db = mysql_select_db("$db", "$c");
		
		$q = "SELECT * FROM 'users' WHERE username = '$username' AND password = '$password'";
		$r = mysql_query("$q", "$c");

		$rws = mysql_num_rows($r);

		if ($rws == "0")
			{
				echo "Login Incorrect! Please go back and try again";
			}
		else
			{
				session_register("username");
				header("Location: admincp.php");
			}
	}

elseif ($id == "logout")
	{
		session_unregister("username");
		session_unset();
		header("Location: index.html");
	}

} // end else
?>
okay, when i access it the first time (for loggin in), it works fine. then when i try to log out, it won't work. i get:

Code: Select all

Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site95/fst/var/www/html/nlogger/config.php:9) in /home/virtual/site95/fst/var/www/html/nlogger/actions.php on line 42
line 9 is:

Code: Select all

require("config.php");
line 42 is:

Code: Select all

header("Location: index.html");
in the config.php:

Code: Select all

$host = "localhost";
$user = "memememe";
$pass = "blablablablabla";
$db = "sinsrevival_com";

// the mysql variables

$dir_name = "/home/virtual/site21/fst/var/www/html/uploads";
$url_name = "http://www.sinsrevival.com/uploads";
any ideas? since if i include the variables in the actions.php, it'll create a huge mess.

-Nay
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Yeah, I saw that:

examplePage.php
Code:

Code: Select all

<?php 
include "databaseInit.php"; 
// some normal non-display code here 
echo "Stuff happens here"; 
header("Location: nextStep.php"); 
// other code for other things... 
include 'cleanUpModule.php'; 
?>

databaseInit.php
Code:

Code: Select all

<?php 
ob_start() // turn output buffering on 
mysql_connect('localhost', 'username', 'password'); 
mysql_select_db('database'); 
?>
But I don't want to connect to the DB from my config.php. I asked since I'm still a little confused about things.

I'm not looking for someone to throw me with the right version of the script. but rather clarify the things I'm doing wrong - which obviously, i'm too stupid to spot it O_o.

-Nay
Post Reply