Zend Session Fatal error - php

I'm having following Zend Session error with my zend project:
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - /home/besthomes/public_html/Zend/Session.php(Line:426): Error #2 session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/besthomes/public_html/Zend/Exception.php:1) Array' in /home/besthomes/public_html/Zend/Session.php:432 Stack trace: #0 /home/besthomes/public_html/index.php(47): Zend_Session::start() #1 {main} thrown in /home/besthomes/public_html/Zend/Session.php on line 432
I have wrote this code in bootstrap file:
include('include.php');
include "Zend/Loader.php";
Zend_Loader::registerAutoload();
Zend_Session::start();
i couldn't know the reason for this error. please help to get out of this problem.
Thanks.

Check if you don't have additional characters in your files. For example -
this code won't trigger an error:
<?php
session_start();
but that one will:
(blank line here!)
<?php
session_start();
Same thing applies to included files. But, when you include files you must also notice to do not have additional lines after clossing tag (if you use them). This will work:
<?php
//content of included file
?>
but something like that won't:
<?php
//content of included file
?>
(blank line here!)
(!and here)
So that's why some people consider not using closing tag in php scripts as good practice.
You can also workaround that problem using ob_start and ob_end_flush, but like I said - it's workaround, not solution.

Somewhere in your code, there is some output being done, which PHP will send the HTTP headers for. Since the HTTP headers are already sent, they cannot be sent again when trying to start the session. If you want to use sessions, starting the session early or first thing is a good idea.
On the other hand, I've seen this error when my app outputs a separate error, thus sending the HTTP headers.
Please have a look at the docs for further information:
http://framework.zend.com/manual/en/zend.session.html
Namely the section called "Starting a Session":
http://framework.zend.com/manual/en/zend.session.advanced_usage.html
Tip:
Remove/comment out the lines that start the session, and see what is output. There may be another error, even unrelated to your code.

Related

Find the root cause of already sent headers in php when entire class is referenced

fellow members and visitors.
Please imbue me of your knowledge and allow me to be enlightened by your expertise by answering this question or providing me a path of exploration.
My simple mind cannot has exhausted the possibilities it was aware and would really like to begin to understand what to do in such a situation should it arise again.
Everything begins with a :
Warning: session_start(): Cannot send session cache limiter - headers
already sent (output started at
/path/to/site/wp-content/themes/theme_name/inc/general/class-Upbootwp_Walker_Nav_Menu.php:125)
in
/path/to/site/wp-content/plugins/wp-php-console/includes/class-wp-php-console.php
on line 142
Here is the exact ubootwp_Walker_Nav_menu.php class for reference.
I am used to having a precise line number in these kind of error but this time, I get no such indicator (I just get the last line, but there's nothing there except the end of the class.
From my understanding, something in that class instantiate a session and when the Worpdress php console plugin try to do it, it crashes as headers were already sent by that class.
I did add the following
error_reporting(E_ALL);
ini_set('display_errors', 'On');
to get the error statement, as I would previously only get a 'error 500'.
I cannot see anything wrong with that class (no obvious echo, print, ob_start).
Does some of you have any clue on how I would go in trying to find the root cause of it ?
Any insight will be appreciated.
edit:
ubootwp_Walker_Nav_menu.php is a UTF-8 file (No BOM)
No hidden characters or anything before php opening tag.
No php closing tag at the end of the file
No echo,ob_start,print or anything obvious that I can see that would initiate a session.
Thoughts:
The error message explicitly states that the error occurs in the php console plugin (which effectively wants to start a session) because the ubootwp_Walker_Nav_menu.php has created the session. Is it possible that the error message is not accurate or does that unequivocaly means that this class is the error ?
Edit 2:
Actually, I thought it was not relevant but I had another notice before the header sent which was:
Strict Standards: Declaration of Upbootwp_Walker_Nav_Menu::start_lvl() should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array) in /home3/i8h1o2r7/public_html/dev/wp-content/themes/axial/inc/general/class-Upbootwp_Walker_Nav_Menu.php on line 130
This was very relevant to the problem as this was the cause of the "header sent". I fixed the declaration from the class which was not causing an issue before and it fixed the PHP console plugin "session already created" issue from the initial message.
The session has to start before ANY html has been sent to the browser. You can turn on output buffering but, it's going to cause problems if run on a server without output buffering enabled ... Doesn't WP start a session anyway?
I found the solution to this problem from Magnus comment reference to another similar question. In my particular case, the header were sent by another notice that was caused by a signature mismatch and outputting headers early.
Strict Standards: Declaration of Upbootwp_Walker_Nav_Menu::start_lvl()
should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth
= 0, $args = Array) in /home3/i8h1o2r7/public_html/dev/wp-content/themes/axial/inc/general/class-Upbootwp_Walker_Nav_Menu.php
on line 130
Once that specific error was fixed, headers were not outputted anymore and the second error (initial question) vanished completely.

PHP mysqli functions fatal ERROR when using the query function

I am programming a website and my current task is to save the text on a mysql server so I can login as admin and then edit the displayed text online.
I already got so far that everything works but I have done it using mysql functions. Now changed all those functions to mysqli ones, since I heard those are way better.
Here is my mysql_connect.php which I created so I could include this in the other scripts wherever I need to connect to the server:
mysql_connect.php
This is my block1_aboutme.php file, where I connect to the server and request all the text from it so I can display it on my "about me" page. This also works as intended and it properly displays the text on my page.
block1_aboutme.php
The problem is when I login as an admin a part of the login verification is this code below in my class.login.php script. As soon as I am logged in and go to my aboutme page an error occurs:
Fatal error: Uncaught Error: Call to a member function query() on unknown in C:\xampp\htdocs\mywebsites\LuPaw\admin\class.login.php:84 Stack trace: #0 C:\xampp\htdocs\mywebsites\LuPaw\admin\class.login.php(73): Login->verifyDatabase() #1 C:\xampp\htdocs\mywebsites\LuPaw\admin\class.login.php(36): Login->verifySession() #2 C:\xampp\htdocs\mywebsites\LuPaw\aboutme.php(42): Login->isLoggedIn() #3 {main} thrown inC:\xampp\htdocs\mywebsites\LuPaw\admin\class.login.php on line 84
This error refers to line 84 which is the $data = $db-> query("select stuff") function.
Somehow this does not work here, while the nearly exact same code line does work in the block1_aboutme script.
I would place the link of my 3rd script here but I can't since I don't have reputation pints yet to place 3 links in one post. Will post 3rd picture in the comments.
I already tried out a few things. If I for example echo out the "$path" it shows the correct path which means $db should be a viable variavble.
Does anyone see the problem here?
Try not to use include_once in your class method as the file will not be included if anywhere during the script execution has been already included: use include instead.
Anyway this is not the best solution you can achieve, I can suggest you to implement a DB class as a singleton and then retrieve the database instance in order to execute your queries.

What is this error and How to solve it Missing argument 2 for PLATFORMS::get_device_info()

I am having this error on my wp multi site ,
Warning: Missing argument 2 for PLATFORMS::get_device_info(), called in /homepages/13/d133448570/htdocs/sogolearn/prosper/tracking202/redirect/rtr.php on line 395 and defined in /homepages/13/d133448570/htdocs/sogolearn/prosper/202-config/connect2.php on line 258
Warning: Cannot modify header information - headers already sent by (output started at /homepages/13/d133448570/htdocs/sogolearn/prosper/202-config/connect2.php:258) in /homepages/13/d133448570/htdocs/sogolearn/prosper/tracking202/redirect/rtr.php on line 286
Page url = http://prosper.sogolearn.com/tracking202/redirect/rtr.php?t202id=8368&t202kw=
Rest of the functions are working properly, no errors on the main site or other domains.
I have no idea what is this error and How to fix it.
The first error is caused by only providing one argument to a function or method that requires at least two arguments. For example, if we have a function like this:
function hasTwoArguments($first, $second) {
// Do something...
}
...then the error occurs if it is called like this:
// The second argument is required, but is not provided, causing an error
hasTwoArguments('first');
The second error is most likely a side-effect of the first error. HTTP headers must be set before any output is sent to the client (the browser in this case). The first error outputs a message (describing what went wrong), which is why the second error occurred.
To fix these errors you have to make sure that the PLATFORMS::get_device_info() method gets two arguments. If you have written the code yourself then you can either provide the second argument, or you can make the second argument optional (if it indeed is optional). If you did not write the code yourself then you should contact the author(s) of the code, telling them that they may have made a mistake.

Why am I getting Warning: Cannot modify header information - headers already sent by (output started at ...)?

I'm reusing a search PHP script, but I get this error:
Warning: Cannot modify header information - headers already sent by
(output started at /Volumes/Work/MAMP/PC
Flag/php_scripts/conection.php:2) in /Volumes/Work/MAMP/PC
Flag/includes/search.php on line 63
line #2 conection.php:
$con = mysqli_connect("localhost", "root", "root", "cms");
line #63 search.php:
header('Location: search-page.php?keywords=' . urlencode($keywords));
What is the problem?
Also I need to mention that the script doesn't redirect me anymore to search-page.php as it should.
When you use header() it shouldn't be any output before, not even a space, you have two solution:
Dirty one
Use ob_clean() before the header to clean the output buffer
ob_clean();
header('Location: search-page.php?keywords=' . urlencode($keywords));
Correct one
Search in your script and your request route for any output, content before <?php, echoes, HTML code, prints or spaces after the ?> are usually the cause of this ;)
Debug
This snippet may help you to find out where is the output in your code:
var_dump(ob_get_contents());die()
Put this before line 63
Javascript workaround
In the case that everything fails, you have another option, use javascript to redirect, although I recommend you to keep trying without get to this point :)
Replace the header(...) with this:
echo '<script>window.location.href="search-page.php?keywords=' . urlencode($keywords)) . '";</script>';
You have send a header already as error states. Please investigate when and how headers are sent.
That usually happens when something is printed before that line to output buffer.
Make sure that you are using UTF-8 without BOM document encoding - BOM sign is invisible in most text editors yet can be interpreted as content which forces sending HTTP headers.
You can debug your output with Output Control function
It's happening because output has been sent already. You can't edit Header Information when you have echo'd anything!
It seems like the error you're getting is because an output have been occured.you can fix it with this code :
if (headers_sent()) {
ob_clean();
}
Just found this detailed answer.

avoid output buffering error in serevr

I am developing w web site. Here I have included a thumnail page. It’s working well in my localhost. But when I uploaded its show me an error see
Warning: Cannot modify header information - headers already sent by (output started at /mydomain/demo1/admin/thumbnail.php:50) in /mydomain/demo1/admin/act-addVehicle.php on line 191
my code
if(move_uploaded_file ($tmpName,$path.$actual_image_name)){
$succ=1;
chmod("$add",0777);
$imgSucc=1;
//strt image thumbnail
include("./thumbnail.php");
// ends
}else{ echo "Failed to upload file Contact Site admin to fix the problem";
exit;}
How I avoid this error
is there any settings in php ini ?
does anyone know ?
please reply
Without seeing thumbnail.php's code its hard to tell exactly what's happening, but basically its outputting something before act-addVehicle.php on line 191 is setting another header.
Most likely a single space at the end of the script. Check after ?> perhaps line 50 if just after.
You could wrap the include('thumbnail.php') into an ob_start() and ob_end_clean() but that will not solve the underlying issue of outputting before setting a new header.
This kind of error typically comes from having a closing php tag in one of your file that is followed by some white space. This white space is sent to the browser when the script is executed BEFORE it executes a "header()" function.
For example, I would not be surprised that your thumbnail.php or act-addverhicule.php ends with a "?>" tag and that there is some white space after it.
As a good practice, it is always better to remove all closing php tag (the "?>") at the end of your files to avoid these kind of problems...
of course. use ob_start funciton somewhere in the beginning of your code

Categories