I just transfer my PHP app, I used to have my app on example.com/app but now I transferred the app to its own domain, othersite.com. My principal site and PHP site are on the same server with apache virtual hosts, it runs on ubuntu 20.xx. The app works fine but I had problems with PHP sessions, when I checked my apache error.log found this
PHP Notice: Undefined index: user_type in /var/www/othersite.com/public_html/index.php on line 66, referer: https://example.com/
and this is what I have on that line,
if( $_SESSION['user_type'] == 'admin' || $_SESSION['user_type'] == 'doctor' || $_SESSION['user_type'] == 'nurse' ) { drawDashboardChecks();}
What do you think could be the problem here?
I didn’t build the app but I guess the code is fine because it worked on the previous site and for some reason, the error log shows me a reference to my principal site.
NOTE: I translated the values on the PHP line.
Thank you.
3
Answers
Well the notice tells – you don’t have that
user_type
key in your array. If its fine, change the check in the way like you don’t actually expectuser_type
to always be there:First there should be checked isset condition..
Check where the Requests are now have been sending, this might be caused because of the URLS that is written in the Forms.
Please look at this example:
And in your login.php page you had a code to handle the request. If the
$_POST['email']
is received, then this simply means that it can be handled, if it’s not received it’s simply undefined index, and you see the error that you are now receiving.Look at the url bellow.
It should be something like this instead.
So please check where are you sending your request before you try to handle them, and the best practice is to use
isset()
php build in function before dealing with indexs.