tuti100 Posted July 21, 2007 Share Posted July 21, 2007 I have two tables login and user(all shown below) DROP TABLE IF EXISTS `login`; CREATE TABLE IF NOT EXISTS `login` ( `username` varchar(20) NOT NULL default '', `password` varchar(20) NOT NULL default '', `user_id` int(11) NOT NULL auto_increment, PRIMARY KEY (`username`) ) TYPE=MyISAM AUTO_INCREMENT=1 ; DROP TABLE IF EXISTS `user`; CREATE TABLE IF NOT EXISTS `user` ( `user_id` int(11) NOT NULL auto_increment, `fname` varchar(20) NOT NULL default '', `lname` varchar(20) NOT NULL default '', `email` text NOT NULL, `user_type` varchar(20) NOT NULL default '', `reg_date` date NOT NULL default '0000-00-00', `street` varchar(40) NOT NULL default '', `building` varchar(40) NOT NULL default '', `organisation` varchar(40) NOT NULL default '', `department` varchar(40) NOT NULL default '', PRIMARY KEY (`user_id`) ) TYPE=MyISAM AUTO_INCREMENT=1 ; I want when the user logs in, he will be valdated and if he exists in the user table, a cookie will be created with the value of the user_id of the user who logged in. How do i do that and be able to pass the value of the cookie to other pages? Also how do i prevent unauthorised users from viewing the other pages apart from home page and login page? How do i achieve pagination while am using a template? Link to comment https://forums.phpfreaks.com/topic/61086-creating-cookie-with-a-value-from-database-during-login/ Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 You may create this using sessions as it may be a bit easier but anyway. When the user logins and the validation is successfull, you create the cookie: setcookie('logged', $username, time()+3600); The cookie created is called 'logged' and has the value of the username. The cookie is saved in the user's local hard drive so it may be called from what page you like. To not let not logged people access pages of your web sites you can use smth like this: if(!isset($_COOKIE['logged'])){ die('You dont have access to this section. Please login first.'); } Link to comment https://forums.phpfreaks.com/topic/61086-creating-cookie-with-a-value-from-database-during-login/#findComment-306068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.