Problems with "headers" too ...

It's not difficult to install myLounge Redirection, but sometimes it's quite tricky. Post your questions in here.

Moderator: Scooby

Problems with "headers" too ...

Postby Fernando » Sun Feb 29, 2004 6:10 pm

Hi!

I have red the last post regarding an error with "headers" and I have one similar to this.
All my script works correctly, users can register new domains, view stats, send a message form "contact", ... etc. But, I have included the file "members.php" into another php file, and when I load this page I can enter a domain and password, script execute "?do=main" correctly and show main page and this error:


Warning: Cannot modify header information - headers already sent by (output started at /home/mundopc/public_html/webmasters/redirect/members.php:2) in /home/mundopc/public_html/webmasters/redirect/myred/include/functions.php on line 250

As you can see, It is an error similar to the last post but in this case, the file is functions.php on line 250.

Well, if you ignore this error and continue navigating, you cannot do it, because any link that you click, always go to login page (to enter again the domain and password)

I have been searching in this file (functions) and this line is to Set Cookie. It seems like if this cookie could not be inserted or installed, but if I execute the file members.php (from myred directory) directly, I can login and click on any link without errors.
In this case, If I deactive cookies on my browser, the effect is the same, you can enter to main page, but whe try to click on any link, goes to login page again.

The question is why cookies are installed correctly when I load members.php directly and they could not install when I load members.php through another php file, that include members.php.

I hope you understand this explanation and can suggest something to solve it.

Thanks. :)
Fernando
Spain
Fernando
 

Some clues...

Postby Fernando » Sun Feb 29, 2004 7:24 pm

Hello again,

I was looking for some clues to resolve this problem and I have found that spaces or break lines can show this kind of errors (as MrSam
said in Michael Kaufman post). Well, if in file where I include members.php delete all before this include, for example, it could be this file,

<?-- file include.php -->
<html>
<head>
....
<?php include ("/myred/members.php"); ?>
....
</html>
</body>

note that I am including members.php into the file include.php. As I said, if I remove all lines before

<?php include ("/myred/members.php"); ?>


( this ones
<?-- file include.php -->
<html>
<head>
....
)

Scripts works correctly and I can navigate into members menus and disconect when I want. In this case, I saw that cookie installs correctly and when I disconnect, system remove cookie without problem.

After that, Is there any manner to make it works without deleting this previous lines? :roll:

Thanks again.
Regards.
Fernando
 

¡ Solved !

Postby Fernando » Tue Mar 02, 2004 1:11 pm

Well, I have found a solution to this tricky problem (at least for me). After read this article:

http://www.zend.com/zend/art/buffering.php

I understand how headers works and If you want to include this script and use cookies, you must to include another funcion very useful in this situations: Output Buffering --> ob_start()

As you can read...

Output Buffering -- How does it work?
When output buffering is enabled, PHP does not send the HTTP header as soon as the script emits output. Instead, it pipes this output into a dynamically growing buffer (this is possible in PHP 4.0, thanks to a centralized output mechanism). You can still modify, add header lines or set cookies, because the header isn't actually sent. In the simplest case, when the script ends, PHP will automatically send the HTTP header, and then the contents of the output buffer, to the browser. I said it was simple!

I hope this will be useful to other webmasters.
Cya! :D
Fernando
 

Postby andelal » Fri Mar 05, 2004 7:40 pm

Thank you for your explaination!

Alex
User avatar
andelal
Site Admin
Site Admin
 
Posts: 479
Joined: Tue Jan 07, 2003 8:53 pm
Location: Vienna/Austria/Europe


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron