I am not a Dummy with PHP but this.....

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
User avatar
TaAngel1962
Forum Newbie
Posts: 10
Joined: Thu Dec 11, 2008 7:26 pm
Contact:

I am not a Dummy with PHP but this.....

Post by TaAngel1962 »

Hi

I am new to this forum, as I have been to so many and have memberships all over the place, and noone can actually tell me how to fix this or a way to find out why on earth after over 1 year this happens to 6 sites I have using this script all at one time........... :banghead: oooooooooooohhhhh. :banghead:

Ok, I am posting the script, I have checked and checked other scripts that have this one page where the error keeps popping up at this certain line 56.

Now the line in Question and giving this awlful headache is going to be in BOLD RED...........Ok !!!!
$_SESSION['sess_data']['mmax'] = $rate;
switch($rate) {
case 1:
$rate = 'ratemin';
break;
case 0:
$rate = 'ratemax';
break;
default:
$rate = 'ratemax';
break;
}
$res = mysql_query("select $rate, ref from acctype, user where acctype.id=user.acctype && user.id=$usrid");
$_SESSION['sess_data']['rate'] = mysql_result($res, 0, $rate);
$_SESSION['sess_data']['ref'] = mysql_result($res, 0, "ref");
$_SESSION['sess_data']['surfing'] = rand(9999, 9999999999);
$_SESSION['sess_data']['from'] = md5($_SESSION['sess_data']['surfing']);
if ($_GET['next'] == md5($_SESSION['sess_data']['surf_encoder_vals'])) {
$s_bar_url = "surfbar.php?PHPSESSID=" . session_id() . "&vc_val=" . $_GET['next'];
} else {
$s_bar_url = "surfbar.php?PHPSESSID=" . session_id() . "&vc_val=begin&coder=". md5($_SESSION['sess_data']['from']);
}
header("Cache-control: private");
echo("<html>\n<head>\n<title>$title: Surf</title>\n<link rel=stylesheet type=text/css href=$self_url" . "style.css>\n</head>\n<frameset rows=$bar_height,* border=0><frame marginheight=0 marginwidth=0 scrolling=no noresize border=0 src=\"$s_bar_url\"><frame marginheight=0 marginwidth=0 scrolling=auto noresize border=0 src=/target.php></frameset>\n</html>");
mysql_close;
exit;
?>

As this copy here I took out the flush() which was above the cache-control : private, and the surfing worked, but now I am getting another error due to this change which another forum told me to do the above, and I am trying to figure out why in the world it would cause another problem, with the header information on line 7 of the logout.php ???

I tried taking out the flush() even in it, and still get this error :

Warning: Cannot modify header information - headers already sent in /home/xxxx/public_html/xxxx/logout.php on line 7

Now I have searched the logout.php, which there isn't mush to search through lol but :

<?php
session_start();
include("vars.php");
$_SESSION = array();
session_destroy();
flush();
header("Location: $self_url?logged-out");
exit;
?>


And as I mentioned never had a problem with this until now, and this script has been up and working great for over a year..........anyone know what to do to tell me to try??

I have 6 sites that this happened to all at once same day. :cry:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: I am not a Dummy with PHP but this.....

Post by requinix »

Don't you also get a message about where the output started?
User avatar
TaAngel1962
Forum Newbie
Posts: 10
Joined: Thu Dec 11, 2008 7:26 pm
Contact:

Re: I am not a Dummy with PHP but this.....

Post by TaAngel1962 »

Hi

Thanks so much for the reply............no I sure don't I wish I did, it would give me more to go on, where to see if I can fix this error. It is getting so frustrating. :banghead:
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: I am not a Dummy with PHP but this.....

Post by novice4eva »

Your source of problem was already answered by tasairis question...
Your problem has been pointed with a red DOT on by the error message.
You have already sent header in logout.php which you must have included in previously posted code(somewhere).

EDIT: headers_sent() function might come handy
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: I am not a Dummy with PHP but this.....

Post by Chris Corbyn »

You're calling flush() in logout.php and then trying to send a header right right you've just sent headers (via flush()).

The error tells you exactly what line to look at.
User avatar
TaAngel1962
Forum Newbie
Posts: 10
Joined: Thu Dec 11, 2008 7:26 pm
Contact:

Re: I am not a Dummy with PHP but this.....

Post by TaAngel1962 »

Hi

Yes on line 7 but I tried taking it out and it still gives this error. I need to know the correct way to code this flush() or just leave it or what?? I am still a newbie at this stuff, but have edited plenty of scripts in php, but this one takes the cake. LOL
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: I am not a Dummy with PHP but this.....

Post by requinix »

novice4eva mentioned using headers_sent: it will tell you on what file and line output began.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: I am not a Dummy with PHP but this.....

Post by novice4eva »

just eat out the flush() line and you are good.
User avatar
TaAngel1962
Forum Newbie
Posts: 10
Joined: Thu Dec 11, 2008 7:26 pm
Contact:

Re: I am not a Dummy with PHP but this.....

Post by TaAngel1962 »

novice4eva wrote:just eat out the flush() line and you are good.
Hi,
I took out the flush() and I still get same error, its not working. I have tried and tried this is what it has in the logout.php :

<?php
session_start();
include("vars.php");
$_SESSION = array();
session_destroy();
flush();
header("Location: $self_url?logged-out");
exit;
?>

By taking the flush() out does not work. Any more Ideas??? PLEASE!!!!!!!!!!!! :banghead:
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Re: I am not a Dummy with PHP but this.....

Post by Jim_Bo »

Hi..

A bandaid, but you could try placing:

Code: Select all

 
ob_start();
 
at the top of your pages
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: I am not a Dummy with PHP but this.....

Post by Mark Baker »

The problem may well be your exit.
Quoting from the manual:
Output a message and terminate the current script
While you're not explicitly outputting any text in your exit, it's entirely possible that PHP is treating it as outputting an empty string, and forcing the headers to be sent first.

Remove the exit, and see whether the error still occurs
User avatar
TaAngel1962
Forum Newbie
Posts: 10
Joined: Thu Dec 11, 2008 7:26 pm
Contact:

Re: I am not a Dummy with PHP but this.....

Post by TaAngel1962 »

Hi

Thanks for replying back, I tried it and I am still getting the same error on same line 7
Warning: Cannot modify header information - headers already sent in /home/xxxxx/public_html/xxxxxx/logout.php on line 7

Now this is how the logout.php looks now, after removing the exit;

<?php
session_start();
include("vars.php");
$_SESSION = array();
session_destroy();
flush();
header("Location: $self_url?logged-out");
?>


Also, I noticed to that I have many .htaccess files in image directories and other directories, :banghead: which I never seen before .........Help!!! :banghead:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: I am not a Dummy with PHP but this.....

Post by Chris Corbyn »

What's in vars.php?

Also, if you have *any* whitespace, including new lines before the opening <?php tags in your files, or after the closing tags you'll get errors like this. Zend say you should not use closing ?> tags at the very end of a script.
User avatar
TaAngel1962
Forum Newbie
Posts: 10
Joined: Thu Dec 11, 2008 7:26 pm
Contact:

Re: I am not a Dummy with PHP but this.....

Post by TaAngel1962 »

:lol: :lol: :lol: :lol: Awesome Thanks!!!!!!!!! Ok this is what I did.

I redone the logout.php and I took out the following lines :

<?php
session_start();
include("vars.php");
$_SESSION = array();
session_destroy();
flush();
header("Location: $self_url?logged-out");
exit;
?>

<?php
ob_start();
session_start();
include("vars.php");
$_SESSION = array();
session_destroy();
header("Location: $self_url?logged-out");
?>

Can you see the difference. I took out the flush() I also done away with the exit; I moved the ob_start at the very top of the <?php> and now it works, the logout .php goes back to the main page again.

But, ended up with another issue after doing this, upon login, the page is to give login credits, and if the member hasnt logged in for awhile it is to refresh them and go into the main members area, but now it just sits and gives refreshing?? The php session isn;'t working right now??? :|

In my opinion this shouldnt have had any effect on what changes I made in the logout.php, nor the .htaccess am I right??
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: I am not a Dummy with PHP but this.....

Post by Chris Corbyn »

Good work :) I'd put your exit() back in though ;)
Post Reply