we moved our website to a new server that came with a new IP address. What puzzles me; the website login sessions do not work on the new server but when I change the database IP to the old server they are working.
MySQL Version
Old server = 5.1.58- Community
New server = 5.1.68 - Community
At first I thought it was a PHP error but I now believe it's not and suspect its MySQL related. Anyone who knows what might have caused this conflict?
Debugging Error
Notice: A session had already been started - ignoring session_start() in C:\inetpub\wwwroot\gtest\libs\products.php on line 2
Notice: Undefined index: uUserTypeID in C:\inetpub\wwwroot\gtest\admin\index.php on line 50
Notice: Undefined offset: 0 in C:\inetpub\wwwroot\gtest\admin\index.php on line 52
Notice: Undefined offset: 0 in C:\inetpub\wwwroot\gtest\admin\index.php on line 52
Line 50
GetUserType($_SESSION['uUserTypeID'], $UserTypeID, $UserTypeDescr, $Active_Tag);
Line 52
if (($UserTypeDescr[0] == 'Admin') || ($UserTypeDescr[0] == 'Report'))
Let's go through the notices in order:
session_start() was already called before. No need to call it again.
There's no such variable as $_SESSION["uUserTypeID"]. It's not set.
The array at $UserTypeDescr doesn't have a 0 index. It's probably empty. If you got it from a database query, it either failed or returned an empty resultset.
Same as 3.
Notice: A session had already been started - ignoring session_start() in C:\inetpub\wwwroot\gtest\libs\products.php on line 2
At a guess session.auto_start is enabled hence the session is being enabled before the session handler is overridden (or the new session handler is failing).
The most safest method of preventing such error (i.e. Session already started) is by always checking if session has already been started before starting a session.
You can do this by simply including
if (!isset($_SESSION))session_start();
I hope this solve the problem? upon trying it, you can simply add your comment or observations to further improve the answer and above all, solve the probelm. I hope this helps?
Related
I am trying to understand if it's correct for PHP to throw an undefined offset error when using isset() function.
The data comes from an eloquent collection.
$interest->vehicles
The problem happens when the collection is empty.
Below code tested on 3 different setups (Mac+Mamp PRO, Windows+Xampp, Mac+Mamp), throws an undefined offset in first two setups but not in mine which is the third one (Mac+Mamp)
All tested scenarios are done with PHP 7 and display errors On.
isset($interest->vehicles[0]['make'])
I understand why the error may be happening to the other setups as the offset i try to isset doesn't exist, but the thing i don't understand is why i don't see the error on my setup when using isset.
I also tried to reinstall Mamp on my maching, upgraded to Sierra OS, restarted my laptop, changed php.ini settings to always display all errors .
ErrorException in Collection.php line 1043:
Undefined offset: 0 (View: /Users/efood-leo/Sites/cardealer/resources/views/panel/interest/form.blade.php) (View: /Users/efood-leo/Sites/cardealer/resources/views/panel/interest/form.blade.php)
This is the error i am talking about, and happens only if i try to retrieve
$interest->vehicles[0]['make']
When the vehicles[0] does not exist.
if i do :
isset($interest->vehicles[0]['make'])
Then there is no error in my setup, and 2 other devs report the error still happens with isset.
Try this code.
Isset() function is returning true somehow so without isset it works
$interest = (object)['vehicles' => []];
echo $interest->vehicles[0]['make'];
Read more on isset():
http://php.net/manual/en/function.isset.php
I am working with opencart and I am learning right now.
When I add discount price in product and save it then I received notice like :
Notice: Undefined index: points in /home/eyelens/public_html/admin/model/catalog/product.php on line 131Notice: Undefined index: points in /home/eyelens/public_html/admin/model/catalog/product.php on line 177Notice: Undefined index: weight in /home/eyelens/public_html/admin/model/catalog/product.php on line 177Notice: Undefined index: weight_prefix in /home/eyelens/public_html/admin/model/catalog/product.php on line 177Warning: Cannot modify header information - headers already sent by (output started at /home/eyelens/public_html/admin/index.php:80) in /home/eyelens/public_html/system/library/response.php on line 12
Here, I got error because my array is full so it can not return point and weight therefor it gives an error. So how can I increase array size ?
Undefined index : Even though php does not need variables to be declared first you must have some values in it before using a variable. So it is recommended that you should initialise the variables or use isset(variablename) before using the variable.
Inorder to solve headers already sent error, you should not print any output before using functions that modify headers like header() session_start()
I have write below two variable in php.ini file
max_input_vars = 30000;
max_post_size = 30000;
and its working perfect.
my moodle site display 'error reading from database'
after activating debugging in config.php error showed that table with name 'mdl_session'
not exist in database
the error message is:
Debug info: Table 'mniknami_edu.mdl_sessions' doesn't exist
SELECT id, sid, state, userid, lastip, timecreated, timemodified FROM mdl_sessions WHERE sid = ?
[array (
0 => 'lhdasq4iscedtqhvbs5j1lq833',
)]
Error code: dmlreadexception
Stack trace:
line 441 of /lib/dml/moodle_database.php: dml_read_exception thrown
line 996 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1415 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
line 1387 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
line 1366 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
line 268 of /lib/classes/session/manager.php: call to moodle_database->get_record()
line 79 of /lib/classes/session/manager.php: call to core\session\manager::initialise_user_session()
line 806 of /lib/setup.php: call to core\session\manager::start()
line 35 of /config.php: call to require_once()
line 27 of /login/index.php: call to require()
my moodle work correctly 2 days ago and Since then, I did not make any changes or update to it
why this problem arise and how i can fixed it?
my moodle version is 2.6.1+
Moodle sessions can be stored in differents places : database, files, memcached. According to https://docs.moodle.org/en/Session_handling the "[files] driver is used by default in new installation".
Perhaps that was the case, but something was recently changed in config.php and Moodle is now trying to use the database for sessions?
On a sidenote, using memcached for session makes a huge difference in performance (as said on Moodle's wiki), but the configuration needs to be done in config.php. If you have memcached available, this could fix the problem and make your site faster.
I ran into the same issue. Check if you are running out of free space in your partitions. If so give it some more space or clean up unused files etc. Turn off binary logs in mysql if you can, those can get really big.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
Okay, so I am trying to build my site and I am having a minor issue. I am getting errors like "Undefined index: id in C:\xampp\htdocs\index.php on line 18"
and
"Undefined index: submit in C:\xampp\htdocs\index.php on line 39"
I am certain it's a matter of syntax but I can't seem to find the right answer. Here is the php code in my index.php file on lines 16-18
session_start();
if($_SESSION['id'] && !isset($_COOKIE['logRemember']) && !$_SESSION['rememberMe'])
The code worked before when I was running Apache 2 in linux. Now I am running Xampp on windows and all of a sudden it doesn't want to work right.
Whoever answers this, please write it in stupid. I'm still learning php. :) Thanks!
No, it's not a syntax error. You are trying to access a key that does not exist. It seems that warnings were disabled on your previous server.
Check if the actual variable is set (using isset) before trying to access it:
if(
isset($_SESSION['id']) &&
!isset($_COOKIE['logRemember']) &&
isset($_SESSION['rememberMe'] &&
!$_SESSION['rememberMe']
)
You use isset() on the $_COOKIE variable, so you must know how that works for checking the existence of a variable. Just apply that to $_SESSION['id'] and so on and the errors will stop.
In your first run, $_SESSION['id'] and $_SESSION['rememberMe'] won't be set.
You have to check if they're set (just as you did with your cookie)
if(isset($_SESSION['id']) && !isset($_COOKIE['logRemember']) && !isset($_SESSION['rememberMe']))
The reason it "worked" was because the Apache 2 server probably wasn't configured to display errors. Your issue is that $_SESSION['id'] isn't set. Rather, check that it is with
isset($_SESSION['id'])
Which won't throw an error if it isn't set.
Check the directory where the session data is storred is writeable by apache. You can get the path by using session_save_path ();
Replce line with following code
session_start();
if(isset($_SESSION['id']) && !isset($_COOKIE['logRemember']) && !isset($_SESSION['rememberMe']))
Using adLDAP.php class
receiving following error: Notice: Undefined index: memberof in /web/ee_web/include/adLDAP.php on line 762
line 762: if (is_array($groups[0]["memberof"])) {
Also receiving error: Notice: Undefined index: count in /web/ee_web/include/adLDAP.php on line 982
line 982: $entries[0]["memberof"]["count"]++;
Unsure of what I need to do to resolve these error messages, it seems that the script is working fine, but I'd like get rid of these errors.
Using: http://adldap.sourceforge.net/wiki/doku.php?id=api
You could edit the code to something along the lines of:
if(isset($groups[0]["memberof"]))
{
if (is_array($groups[0]["memberof"])){ ... }
}
And
if(isset($entries[0]["memberof"]["count"]))
{
$entries[0]["memberof"]["count"]++;
}
It will keep you from getting the errors, though it won't necessarily handle some pretty lax sanity checking by the original author of the code.
It seems like you have your error_level set to show every possible error/warning/notice, that's why you're getting it.
If the script is working fine, then it's not an error, simply a missing check the coder forgot to put in the library.
To get rid of thos messages, you have 2 options:
a) Use # before the calls you do to that library, such as
$var = #the_function(param1);
This will avoid those messages for just that line.
b) Set the error level to something like this with error_reporting():
error_reporting(E_ALL ^ E_NOTICE);
This will affect the whole script you're running.
It's up to you what to use depending on the project.