How can i simply check if cookies are enabled and user session too in PHP?
I need the really lighter piece of code of this world to do that, can anyone show me somenthing?
I'm on Codeigniter but i'm planning to use native PHP for this control.
my code:
if(session_start()){ echo 'started'; }
as i know Codeigniter doesn't uses native PHP session, how to do so?
CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.
CodeIgniter is still exist but the name of this framework has become synonymous with a low-quality solution that is why we advise you Laravel as a better alternative. Both Laravel and CodeIgniter are open-source PHP framework.
Front-end web development Expertise in creating high-quality CodeIgniter web applications and advanced portals that are fully functional and add value to a business enterprise.
Key Difference : Laravel is relational object-oriented and CodeIgniter is Object-oriented. Laravel provides authentication class features and CodeIgniter does not have built-in authentication features. Laravel has inbuilt unit testing tool and CodeIgniter does not have inbuilt unit testing tool.
Check for a valid session id:
$sid = session_id();
For example:
$sid = session_id();
if($sid) {
echo "Session exists!";
} else {
session_start();
}
The first point is "Don't fight the framework" when your framework has some functions than use it. Normally in the Framework classes are functions to prevent injections.
Here is a Post when tells you how to check the cookie:
Check if cookies are enabled
And for the session
How to tell if a session is active?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With