Jump to content

header(); Problem


DarkHavn

Recommended Posts

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

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


(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 :(

Link to comment
Share on other sites

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

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:

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

Ken
Link to comment
Share on other sites

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

}






}


[/code]
Link to comment
Share on other sites

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

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


}




[/code]

lines 130-146
Link to comment
Share on other sites

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:
[code]mysql_query('$errorquery');[/code]
Change that to:
[code]mysql_query($errorquery);[/code]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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 :)


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.