Jump to content


Photo

header(); Problem


  • Please log in to reply
11 replies to this topic

#1 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 26 August 2006 - 01:04 PM

I don't know what is going on, everything with my process.php script was running fine.

Then all of a sudden i turned on my laptop and the whole process.php script is falling apart, every header(); i have done in for re-direction to other pages after insering, or looking through the database.

Dunno whats going on, but the header i have is on line 57 (of a 300odd line process page) that is the first header and it stuffs up, heres the following code up till that line

	//Welcome to the process page, 
	
	//The following are functions for connecting to the database
	function connect() {
	mysql_connect('localhost', 'root', '');
	mysql_select_db('localfind');
	}
		
		//The current function selects the agent database and selects all information so it can easily be searched
		//if it doesnt connect the proper actions are taking and the ip and error message are recorded into the database
		
		function agentdb_select() {
		connect();
			if(mysql_select_db('agent')) {
				$query ='SELECT * FROM agent';
				mysql_query("$query");
			
			} else {
				mysql_select_db('information');
				$error = mysql_error();
				$query = 'INSERT INTO INTO information (ip, error) VALUES (' . "$ip" . "$error" . ')';
					mysql_query("$query");
			
			 }
			
		
			}
	
	//The following is used for encryption purposes (md5())
	
	function encrypt($pass) {
	md5("$value");
	}
	
	//The following functions are for security, stripping the slashes and going through all of the input from the forms
	//to make sure there isn't anything that isn't supposed to be inserted into the database.
	//Strips tags and slashes and replaces with the correct measures
	
	function clean($post) {
	strip_tags("$value");
	stripslashes("$value");
	}
	
	
	
	
	/*if($_POST['newclient']){
	header('location: ../newagent/newagent.php');
	}
	*/
	
	//This section receives the post and sets a session variable because the stupid php query link didn't
	//seem to like my mysql and phpadmin lol
	
	if($_POST['newagent']) {
	header("Location: ../newagent/newagent.php");
		} 


(If you look closley the first 50 od lines are mainly //comments)

Please guys any help would be appreciated im really stuck and only have a few hours left to debug this :(



#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 August 2006 - 01:20 PM

If "everything" was working and "suddenly" it's not, what did you change?

Also, what do you mean by "it's not working" -- errors, results, non-results, what is it doing or not doing.

Just a few comments:

These two functions don't do anything:
<?php
	function encrypt($pass) {
	md5("$value");
	}
	
	//The following functions are for security, stripping the slashes and going through all of the input from the forms
	//to make sure there isn't anything that isn't supposed to be inserted into the database.
	//Strips tags and slashes and replaces with the correct measures
	
	function clean($post) {
	strip_tags("$value");
	stripslashes("$value");
	}
?>

In order for them to do anything, you need to do something with the variable you pass to the functions and return the value, something like:

<?php
	function encrypt($pass) {
	    return(md5($pass));
	}
	
	//The following functions are for security, stripping the slashes and going through all of the input from the forms
	//to make sure there isn't anything that isn't supposed to be inserted into the database.
	//Strips tags and slashes and replaces with the correct measures
	
	function clean($post) {
	      return (striptags(stripslashes($post)));
	}
?>

Ken

#3 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 26 August 2006 - 01:42 PM

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\xampp\htdocs\localfind\process\process.php:141) in C:\xampp\xampp\htdocs\localfind\process\process.php on line 152

Thats one of the errors that im getting, it's continously that, and now even my mysql queries with mysql_num_rows condition statement isn't working either.

The only thing i had been building on was a search function, but i commented that out to see if that was what was stuffing around with everything but it hasn't.

It's weird, lol and very unexpected. Can header(); stuff up on it's self, is there anyway to clear the header or something long those lines?

for my mysql_num_rows i have the following
if($_POST['cata2']) {
	connect();
	$username = $_POST['agentlogin'];
	$pass = md5($_POST['agentpass']);
	
	$mysqlquery = "SELECT * FROM agent WHERE `names`='$username' AND `pass`='$pass'";
	$mysqlquery2 = mysql_query("$mysqlquery");
	
		if(mysql_num_rows(mysql_query("SELECT * FROM agent WHERE `names`='$username' AND `pass`='$pass'") ==  1)) {
			$loggedinquery = "UPDATE agent SET loggedin='1' WHERE `name`='$username' ";
				mysql_query("$loggedinquery");
				$_SESSION['username'] = $username;
				$_SESSION['login'] = true;
				unset($username);
				unset($pass);
				header("Location: ../newagent/newagent.php");	
					
		} else {
		$_SESSION['loginerror'] = "Sorry the information you supplied was Incorrect, try again.";
		header("Location: ../newagent/newagent.php");
		
		}
	
	
	
	
	
	
	}
	
	


#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 August 2006 - 02:06 PM

What's a line 152 of process.php? That's where PHP think's you've written something to the screen.

Ken

#5 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 26 August 2006 - 02:43 PM

That's the thing, ive debugged it all and went through it, everything above it, and after it is working properly, that's why i can understand why the header won't redirect.

There is nothing being outputted before the redirection happens, it's fucked up.

I'm currently just going through the script and making small alterations to get alet a temp set up for the presentation tomorrow so some redirection works.

I have no idea to what it could be though.

Line 152 was a simple

if($_POST['login']){
//connects to the database and checks the information is really the users
//then redirects
}

debugged that 50 times over, the queries work, and find the user, but then it wont redirect

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 August 2006 - 03:49 PM

Somewhere the script is sending a character to the screen. Did you read the sticky topic at the top of thie forum here?  Are you sure you have no unseen characters before the first "<?php"?

Ken

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 August 2006 - 03:52 PM

According to the error some from of output was detected around line 141 in process.php. Post the code from lines 136 through to 146 here.

#8 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 26 August 2006 - 03:56 PM

	if($_POST['logout']) {
	connect();
	//$logout =  ;
	$username = $_SESSION['username'];
	$logout = "UPDATE agent SET `loggedin`='0' WHERE `name`='$username';";
		if(mysql_query("$logout")) {
		$_SESSION['login'] = false;
		header("Location: ../index.php");
		}else {
		$error = mysql_error();
			$ip = $_SERVER['REMOTE_ADDR'];
			$errorquery = "INSERT INTO information (`error`, `ip`) VALUES ('$error', '$ip');";
				mysql_query('$errorquery');
		}
	//header("Location: ../index.php");
	
	
	}
	
	



lines 130-146

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 August 2006 - 04:04 PM

How strange. Everthink is fine there. Not sure then. Is this the ony error message you get. Do you get any notice messages or any other error messages.

The only thing I can see that isnt ok which is this:
mysql_query('$errorquery');
Change that to:
mysql_query($errorquery);


#10 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 26 August 2006 - 04:08 PM

i just got errors back from the headers(); and also my mysql_fetch_assoc, and mysql_num_rows, but ive debugged them all and they work fine, it's really confusing lol


Think i might just redo the thing again it's starting to piss me off


#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 August 2006 - 04:12 PM

There is one more option which I dont like when it comes to this. Its to use output buffering.

Add ob_start(); at the top of process.php. so it is just under <?php

and add ob_end_flush(); at the bottom of process.php so its just before ?>

Do you get any errors now?

#12 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 26 August 2006 - 04:28 PM

ah its abit late to go back now, i'm redoing the process page, and going through it section by section, and clearing up anything.

Cheers for the help though, i will mark this solved for now. But if the problem still appears when i try the process.php page again i will try your advice and post another topic.

Cheers for the help :)







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users