PHP - Login Via Php And Cookies
Alright, I'm struggling a bit. I've succesfully set up a MySQL database and users can register.
I also have a login script which works. However, what I want to do now is make it so a user has his information saved in a cookie for 100 days unless he logs out. (I will implement this into a remember me checkbox, but after I get it working this way first.) So a user logs in using a form which fills in appropriate variables, and this script is run: (obviously the stars are not in the script, I have correct log in there.) Code: [Select] <?php ob_start(); $host="localhost"; // Host name $username="****"; // Mysql username $password="****"; // Mysql password $db_name="users"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row setcookie('username', $_POST['myusername'], time()+60*60*24*365); setcookie('password', md5($_POST['mypassword']), time()+60*60*24*365); if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> You'll see the cookie is near the end. I then go to a page which includes this: Code: [Select] <?php if(isset($_COOKIE['username'])) { echo 'You are logged in as', var_dump($_COOKIE); } else { echo 'you aren\'t logged in!'; } ?> Which simply looks for the cookie. However, no matter what I try, it seems to not detect the cookie, and it says I am not logged in. Does anyone spot the problem? Similar TutorialsHey All, I have been struggling with this for the last few days and really cannot work out why this is not working. I am building a PHP login system and cannot get the Set Cookies function when I add the it to the website template. I have created a PHP file with nothing but a login form and the code to set a cookie, then divert to index.php page. This works perfectly! But when I use this within the website template i have it suddenly stops working! Any input would be much appreciated as I am running out of things to try.
Basic PHP File (that works): <?php //login.php include 'db_const.php'; if(isset($_COOKIE["user_id"])) { header("location:index.php"); } $message = ''; if(isset($_POST["login"])) { if(empty($_POST["user_email"]) || empty($_POST["user_password"])) { $message = "<div class='alert alert-danger'>Both Fields are required</div>"; } else { $query = " SELECT * FROM user_details WHERE user_email = :user_email"; $statement = $connect->prepare($query); $statement->execute( array( 'user_email' => $_POST["user_email"] ) ); $count = $statement->rowCount(); if($count > 0) { $result = $statement->fetchAll(); foreach($result as $row) { if(password_verify($_POST["user_password"], $row["user_password"])) //// Check PHP HASH ///////////// { setcookie("user_id", $row["user_id"], time()+86400); header("location:index.php"); } else { $message = '<div class="alert alert-danger">Wrong Password</div>'; } } } else { $message = "<div class='alert alert-danger'>Wrong Email Address</div>"; } } } ?> <!DOCTYPE html> <html> <head> <title>How to create PHP Login Script using Cookies</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <br /> <div class="container"> <h2 align="center">How to create PHP Login Script using Cookies</h2> <br /> <div class="panel panel-default"> <div class="panel-heading">Login</div> <div class="panel-body"> <span><?php echo $message; ?></span> <form method="post"> <div class="form-group"> <label>User Email</label> <input type="text" name="user_email" id="user_email" class="form-control" /> </div> <div class="form-group"> <label>Password</label> <input type="password" name="user_password" id="user_password" class="form-control" /> </div> <div class="form-group"> <input type="submit" name="login" id="login" class="btn btn-info" value="Login" /> </div> </form> </div> </div> <br /> <p>Admin email - john_smith@gmail.com</p> <p>Admin Password - password</p> <p>All user password is 'password'</p> </div> </body> </html> PHP file with design: <?php include 'db_const.php'; if(isset($_COOKIE["id"])) { header("location:index.php"); } $message = ''; if(isset($_POST["login"])) { if(empty($_POST["user_email"]) || empty($_POST["user_password"])) { $message = "<div class='alert alert-danger'>Both Fields are required</div>"; } else { $query = " SELECT * FROM user_details WHERE user_email = :user_email"; $statement = $connect->prepare($query); $statement->execute( array( 'user_email' => $_POST["user_email"] ) ); $count = $statement->rowCount(); if($count > 0) { $result = $statement->fetchAll(); foreach($result as $row) { if(password_verify($_POST["user_password"], $row["user_password"])) //// Check PHP HASH ///////////// { setcookie("user_id", $row["user_id"], time()+86400); header("location:index.php"); } else { $message = '<div class="alert alert-danger">Wrong Password</div>'; } } } else { $message = "<div class='alert alert-danger'>Wrong Email Address</div>"; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <!--[if IE]> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <![endif]--> <meta name="description" content=""> <meta name="author" content="ScriptsBundle"> <title>AdForest | Largest Classifieds Portal</title> <!-- =-=-=-=-=-=-= Favicons Icon =-=-=-=-=-=-= --> <link rel="icon" href="images\favicon.ico" type="image/x-icon"> <!-- =-=-=-=-=-=-= Mobile Specific =-=-=-=-=-=-= --> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <!-- =-=-=-=-=-=-= Bootstrap CSS Style =-=-=-=-=-=-= --> <link rel="stylesheet" href="css\bootstrap.css"> <!-- =-=-=-=-=-=-= Template CSS Style =-=-=-=-=-=-= --> <link rel="stylesheet" href="css\style.css"> <!-- =-=-=-=-=-=-= Font Awesome =-=-=-=-=-=-= --> <link rel="stylesheet" href="css\font-awesome.css" type="text/css"> <!-- =-=-=-=-=-=-= Flat Icon =-=-=-=-=-=-= --> <link href="css\flaticon.css" rel="stylesheet"> <!-- =-=-=-=-=-=-= Et Line Fonts =-=-=-=-=-=-= --> <link rel="stylesheet" href="css\et-line-fonts.css" type="text/css"> <!-- =-=-=-=-=-=-= Menu Drop Down =-=-=-=-=-=-= --> <link rel="stylesheet" href="css\forest-menu.css" type="text/css"> <!-- =-=-=-=-=-=-= Animation =-=-=-=-=-=-= --> <link rel="stylesheet" href="css\animate.min.css" type="text/css"> <!-- =-=-=-=-=-=-= Select Options =-=-=-=-=-=-= --> <link href="css\select2.min.css" rel="stylesheet"> <!-- =-=-=-=-=-=-= noUiSlider =-=-=-=-=-=-= --> <link href="css\nouislider.min.css" rel="stylesheet"> <!-- =-=-=-=-=-=-= Listing Slider =-=-=-=-=-=-= --> <link href="css\slider.css" rel="stylesheet"> <!-- =-=-=-=-=-=-= Owl carousel =-=-=-=-=-=-= --> <link rel="stylesheet" type="text/css" href="css\owl.carousel.css"> <link rel="stylesheet" type="text/css" href="css\owl.theme.css"> <!-- =-=-=-=-=-=-= Check boxes =-=-=-=-=-=-= --> <link href="skins\minimal\minimal.css" rel="stylesheet"> <!-- =-=-=-=-=-=-= Responsive Media =-=-=-=-=-=-= --> <link href="css\responsive-media.css" rel="stylesheet"> <!-- =-=-=-=-=-=-= Template Color =-=-=-=-=-=-= --> <link rel="stylesheet" id="color" href="css\colors\defualt.css"> <!-- =-=-=-=-=-=-= For Style Switcher =-=-=-=-=-=-= --> <link rel="stylesheet" id="theme-color" type="text/css" href="#"> <!-- =-=-=-=-=-=-= Check boxes =-=-=-=-=-=-= --> <link href="skins\minimal\minimal.css" rel="stylesheet"> <!-- JavaScripts --> <script src="js\modernizr.js"></script> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <!-- =-=-=-=-=-=-= Light Header =-=-=-=-=-=-= --> <div class="colored-header"> <!-- Top Bar --> <div class="header-top"> <div class="container"> <div class="row"> <!-- Header Top Left --> <div class="header-top-left col-md-8 col-sm-6 col-xs-12 hidden-xs"> <ul class="listnone"> <li><a href="about.html"><i class="fa fa-heart-o" aria-hidden="true"></i> About</a></li> <li><a href="faqs.html"><i class="fa fa-folder-open-o" aria-hidden="true"></i> FAQS</a></li> </ul> </div> <!-- Header Top Right Social --> <div class="header-right col-md-4 col-sm-6 col-xs-12 "> <div class="pull-right"> <ul class="listnone"> <?php if(empty($user_id)) { echo("<li><a href=\"login.php\"><i class=\"fa fa-sign-in\"></i> Log in</a></li> <li><a href=\"register.php\"><i class=\"fa fa-unlock\" aria-hidden=\"true\"></i> Register</a></li></ul>"); } else { echo("<li class=\"dropdown\"> <a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" role=\"button\" aria-haspopup=\"true\" aria-expanded=\"false\"><i class=\"icon-profile-male\" aria-hidden=\"true\"></i>Test<span class=\"caret\"></span></a> <ul class=\"dropdown-menu\"> <li><a href=\"profile.php\">User Profile</a></li> <li><a href=\"archives.html\">Archives</a></li> <li><a href=\"active-ads.html\">Active Ads</a></li> <li><a href=\"pending-ads.html\">Pending Ads</a></li> <li><a href=\"favourite.html\">Favourite Ads</a></li> <li><a href=\"messages.html\">Message Panel</a></li> <li><a href=\"deactive.html\">Account Deactivation</a></li> <li><a href=\"logout.php\">Log Out</a></li>"); } ?> </ul> </div> </div> </div> </div> </div> <!-- Top Bar End --> <!-- Navigation Menu --> <nav id="menu-1" class="mega-menu"> <!-- menu list items container --> <section class="menu-list-items"> <div class="container"> <div class="row"> <div class="col-lg-12 col-md-12"> <!-- menu logo --> <ul class="menu-logo"> <li> <a href="index.html"><img src="images\logo.png" alt="logo"> </a> </li> </ul> <!-- menu links --> <ul class="menu-links"> <!-- active class --> <li> <a href="javascript:void(0)"> Home <i class="fa fa-angle-down fa-indicator"></i></a> <div class="drop-down grid-col-8"> <!--grid row--> <div class="grid-row"> <!--grid column 3--> <div class="grid-col-4"> <ul> <li><a href="index.html">Home 1 - Default </a></li> <li><a href="index-transparent.html">Home 2 (Transparent)</a></li> <li><a href="index-2.html">Home 3 (Variation)</a></li> <li><a href="index-3.html">Home 4 (Master Slider)</a></li> </ul> </div> <div class="grid-col-4"> <ul> <li><a href="index-4.html">Home 5 (With Map Listing)</a></li> <li><a href="index-5.html">Home 6 (Modern Style)</a></li> <li><a href="index-6.html">Home 7 (Variation)</a></li> <li><a href="index-7.html">Home 8 (Category Slider)</a></li> </ul> </div> <div class="grid-col-4"> <ul> <li><a href="index-10.html">Home 11 (Modern Home)</a></li> <li><a href="index-8.html">Home 9 (Landing Page)</a></li> <li><a href="index-9.html">Home 10 (Variation)</a></li> </ul> </div> </div> </div> </li> <li> <a href="javascript:void(0)">Listing <i class="fa fa-angle-down fa-indicator"></i></a> <!-- drop down multilevel --> <ul class="drop-down-multilevel"> <li> <a href="javascript:void(0)">Grid Style<i class="fa fa-angle-right fa-indicator"></i> <span class="label label-info">New</span></a> <!-- drop down second level --> <ul class="drop-down-multilevel"> <li><a href="listing.html">Listing Grid 1</a></li> <li><a href="listing-1.html">Listing Grid 2</a></li> <li><a href="listing-2.html">Listing Grid 3</a></li> <li><a href="listing-7.html">Listing Featured <span class="label label-info">New</span></a></li> </ul> </li> <li> <a href="javascript:void(0)">List Style<i class="fa fa-angle-right fa-indicator"></i> </a> <!-- drop down second level --> <ul class="drop-down-multilevel"> <li><a href="listing-3.html">List View 1</a></li> <li><a href="listing-4.html">List View 2</a></li> <li><a href="listing-5.html">List View 3</a></li> <li><a href="listing-6.html">List View 4</a></li> </ul> </li> <li> <a href="javascript:void(0)">Single Ad<i class="fa fa-angle-right fa-indicator"></i> <span class="label label-info">New</span></a> <!-- drop down second level --> <ul class="drop-down-multilevel"> <li><a href="single-page-listing.html">Single Ad Detail</a></li> <li><a href="single-page-listing-featured.html">Ad (Featured) <span class="label label-info">New</span></a></li> <li><a href="single-page-listing-2.html">Single Ad 2</a></li> <li><a href="single-page-listing-3.html">Single Ad (Adsense)</a></li> <li><a href="single-page-expired.html">Single Ad (Closed)</a></li> </ul> </li> <li><a href="icons.html">Classified Icons </a></li> </ul> </li> <li> <a href="javascript:void(0)">Categories <i class="fa fa-angle-down fa-indicator"></i></a> <!-- drop down multilevel --> <ul class="drop-down-multilevel"> <li><a href="category-2.html">Modern Variation</a></li> <li><a href="category-3.html">Minimal Variation</a></li> <li><a href="category-4.html">Fancy Variation</a></li> <li><a href="category-6.html">Flat Variation</a></li> </ul> </li> <li> <a href="javascript:void(0)">Dashboard <i class="fa fa-angle-down fa-indicator"></i></a> <!-- drop down multilevel --> <ul class="drop-down-multilevel"> <li><a href="profile.html">User Profile</a></li> <li><a href="profile-2.html">User Profile 2</a></li> <li><a href="archives.html">Archives</a></li> <li><a href="active-ads.html">Active Ads</a></li> <li><a href="pending-ads.html">Pending Ads</a></li> <li><a href="favourite.html">Favourite Ads</a></li> <li><a href="messages.html">Message Panel</a></li> <li><a href="deactive.html">Account Deactivation</a></li> </ul> </li> <li> <a href="javascript:void(0)">Pages <i class="fa fa-angle-down fa-indicator"></i></a> <!-- drop down full width --> <div class="drop-down grid-col-12"> <!--grid row--> <div class="grid-row"> <!--grid column 2--> <div class="grid-col-3"> <h4>Blog</h4> <ul> <li><a href="blog.html">Blog With Right Sidebar</a></li> <li><a href="blog-1.html">Blog With Masonry Style</a></li> <li><a href="blog-2.html">Blog Without Sidebar</a></li> <li><a href="blog-details.html">Single Blog </a></li> <li><a href="blog-details-1.html">Single Blog (Adsense) </a></li> </ul> </div> <!--grid column 2--> <div class="grid-col-3"> <h4>Miscellaneous</h4> <ul> <li><a href="about.html">About Us</a></li> <li><a href="cooming-soon.html">Comming Soon</a></li> <li><a href="elements.html">Shortcodes</a></li> <li><a href="error.html">404 Page</a></li> <li><a href="faqs.html">FAQS</a></li> </ul> </div> <!--grid column 2--> <div class="grid-col-3"> <h4>Others</h4> <ul> <li><a href="login.html">Login</a></li> <li><a href="register.html">Register</a></li> <li><a href="pricing.html">Pricing</a></li> <li><a href="site-map.html">Site Map</a></li> <li><a href="post-ad-1.html">Post Ad</a></li> </ul> </div> <!--grid column 2--> <div class="grid-col-3"> <h4>Detail Page</h4> <ul> <li><a href="post-ad-2.html">Post Ad 2</a></li> <li><a href="single-page-listing.html">Single Ad Detail</a></li> <li><a href="single-page-listing-2.html">Single Ad 2</a></li> <li><a href="single-page-listing-3.html">Single Ad (Adsense)</a></li> <li><a href="single-page-expired.html">Single Ad (Closed)</a></li> </ul> </div> <!--grid column 2--> </div> </div> </li> <li> <a href="javascript:void(0)">Drop Down <i class="fa fa-angle-down fa-indicator"></i></a> <!-- drop down multilevel --> <ul class="drop-down-multilevel"> <li><a href="#">Item one</a></li> <li> <a href="javascript:void(0)">Items Right Side <i class="fa fa-angle-right fa-indicator"></i> </a> <!-- drop down second level --> <ul class="drop-down-multilevel"> <li> <a href="javascript:void(0)"> <i class="fa fa-buysellads"></i> Level 2 <i class="fa fa-angle-right fa-indicator"></i></a> <!-- drop down third level --> <ul class="drop-down-multilevel"> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> </ul> </li> <li> <a href="javascript:void(0)"> <i class="fa fa-dashcube"></i> Level 2 <i class="fa fa-angle-right fa-indicator"></i></a> <!-- drop down third level --> <ul class="drop-down-multilevel"> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> </ul> </li> <li> <a href="javascript:void(0)"> <i class="fa fa-heartbeat"></i> Level 2 <i class="fa fa-angle-right fa-indicator"></i></a> <!-- drop down third level --> <ul class="drop-down-multilevel"> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> </ul> </li> <li> <a href="javascript:void(0)"> <i class="fa fa-medium"></i> Level 2 <i class="fa fa-angle-right fa-indicator"></i></a> <!-- drop down third level --> <ul class="drop-down-multilevel"> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> </ul> </li> <li> <a href="javascript:void(0)"> <i class="fa fa-leanpub"></i> Level 2 <i class="fa fa-angle-right fa-indicator"></i> </a> <!-- drop down third level --> <ul class="drop-down-multilevel"> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> </ul> </li> </ul> </li> <li><a href="#">Item 2</a></li> <li> <a href="javascript:void(0)">Items Left Side <i class="fa fa-angle-left fa-indicator"></i> </a> <!-- add class left-side --> <ul class="drop-down-multilevel left-side"> <li> <a href="#"> <i class="fa fa-forumbee"></i> Level 2</a> </li> <li> <a href="#"> <i class="fa fa-hotel"></i> Level 2</a> </li> <li> <a href="#"> <i class="fa fa-automobile"></i> Level 2</a> </li> <li> <a href="javascript:void(0)"> <i class="fa fa-heartbeat"></i> Level 2 <i class="fa fa-plus fa-indicator"></i> </a> <!--drop down second level--> <ul class="drop-down-multilevel"> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> <li><a href="#">Level 3</a></li> </ul> </li> <li> <a href="#"> <i class="fa fa-bookmark"></i> Level 2</a> </li> <li> <a href="#"> <i class="fa fa-bell"></i> Level 2</a> </li> <li> <a href="#"> <i class="fa fa-soccer-ball-o"></i> Level 2</a> </li> <li> <a href="#"> <i class="fa fa-life-ring"></i> Level 2</a> </li> </ul> </li> <li><a href="#">Item 4</a> </li> </ul> </li> <li><a href="contact.html">Contact </a></li> </ul> <ul class="menu-search-bar"> <li> <a href="post-ad-1.html" class="btn btn-light"><i class="fa fa-plus" aria-hidden="true"></i> Post Free Ad</a> </li> </ul> </div> </div> </div> </section> </nav> </div> <!-- Navigation Menu End --> <!-- =-=-=-=-=-=-= Light Header End =-=-=-=-=-=-= --> <!-- =-=-=-=-=-=-= Transparent Breadcrumb =-=-=-=-=-=-= --> <div class="page-header-area"> <div class="container"> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <div class="header-page"> <h1>User Sign In</h1> </div> </div> </div> </div> </div> <!-- Small Breadcrumb --> <div class="small-breadcrumb"> <div class="container"> <div class=" breadcrumb-link"> <ul> <li><a href="index.html">Home Page</a></li> <li><a class="active" href="#">Sign In</a></li> </ul> </div> </div> </div> <!-- Small Breadcrumb --> <!-- =-=-=-=-=-=-= Transparent Breadcrumb End =-=-=-=-=-=-= --> <!-- =-=-=-=-=-=-= Main Content Area =-=-=-=-=-=-= --> <div class="main-content-area clearfix"> <!-- =-=-=-=-=-=-= Latest Ads =-=-=-=-=-=-= --> <section class="section-padding error-page pattern-bg "> <!-- Main Container --> <div class="container"> <!-- Row --> <div class="row"> <!-- Middle Content Area --> <div class="col-md-5 col-md-push-7 col-sm-6 col-xs-12"> <!-- Form --> <span><?php echo $message; ?></span> <div class="form-grid"> <form method="post"> <div class="form-group"> <label>Email</label> <input type="text" name="user_email" id="user_email" class="form-control" /> </div> <div class="form-group"> <label>Password</label> <input type="password" name="user_password" id="user_password" class="form-control" /> </div> <div class="form-group"> <div class="row"> <div class="col-xs-12"> <div class="skin-minimal"> <ul class="list"> <li> <input type="checkbox" id="minimal-checkbox-1"> <label for="minimal-checkbox-1">Remember Me</label> </li> </ul> </div> </div> </div> </div> <input type="submit" name="login" id="login" class="btn btn-info" value="Login" /> </form> </div> <!-- Form --> </div> <div class="col-md-7 col-md-pull-5 col-xs-12 col-sm-6"> <div class="heading-panel"> <h3 class="main-title text-left"> Sign In to your account </h3> </div> <div class="content-info"> <div class="features"> <div class="features-icons"> <img src="images\icons\chat.png" alt="img"> </div> <div class="features-text"> <h3>Chat & Messaging</h3> <p> Access your chats and account info from any device. </p> </div> </div> <div class="features"> <div class="features-icons"> <img src="images\icons\panel.png" alt="img"> </div> <div class="features-text"> <h3>User Dashboard</h3> <p> Maintain a wishlist by saving your favourite items. </p> </div> </div> <span class="arrowsign hidden-sm hidden-xs"><img src="images\arrow.png" alt=""></span> </div> </div> <!-- Middle Content Area End --> </div> <!-- Row End --> </div> <!-- Main Container End --> </section> <!-- =-=-=-=-=-=-= Ads Archives End =-=-=-=-=-=-= --> <!-- =-=-=-=-=-=-= FOOTER =-=-=-=-=-=-= --> <footer> <!-- Footer Content --> <div class="footer-top"> <div class="container"> <div class="row"> <div class="col-md-3 col-sm-6 col-xs-12"> <!-- Info Widget --> <div class="widget"> <div class="logo"> <img alt="" src="images\logo-1.png"> </div> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur et dolor eget erat fringilla port.</p> <ul> <li><img src="images\appstore.png" alt=""></li> <li><img src="images\googleplay.png" alt=""></li> </ul> </div> <!-- Info Widget Exit --> </div> <div class="col-md-3 col-sm-6 col-xs-12"> <!-- Follow Us --> <div class="widget socail-icons"> <h5>Follow Us</h5> <ul> <li><a class="fb" href=""><i class="fa fa-facebook"></i></a><span>Facebook</span></li> <li><a class="twitter" href=""><i class="fa fa-twitter"></i></a><span>Twitter</span></li> <li><a class="linkedin" href=""><i class="fa fa-linkedin"></i></a><span>Linkedin</span></li> <li><a class="googleplus" href=""><i class="fa fa-google-plus"></i></a><span>Google+</span></li> </ul> </div> <!-- Follow Us End --> </div> <div class="col-md-6 col-sm-6 col-xs-12"> <!-- Newslatter --> <div class="widget widget-newsletter"> <h5>Singup for Weekly Newsletter</h5> <div class="fieldset"> <p>We may send you information about related events, webinars, products and services which we believe.</p> <form> <input class="" value="Enter your email address" type="text"> <input class="submit-btn" name="submit" value="Submit" type="submit"> </form> </div> </div> <!-- Newslatter --> </div> </div> </div> </div> <!-- Copyrights --> <div class="copyrights"> <div class="container"> <div class="copyright-content"> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <p>© 2017 AForest All rights reserved. Design by <a href="http://themeforest.net/user/scriptsbundle/portfolio" target="_blank">Scriptsbundle</a> </p> </div> </div> </div> </div> </div> </footer> <!-- =-=-=-=-=-=-= FOOTER END =-=-=-=-=-=-= --> </div> <!-- Main Content Area End --> <!-- Post Ad Sticky --> <a href="#" class="sticky-post-button hidden-xs"> <span class="sell-icons"> <i class="flaticon-transport-9"></i> </span> <h4>SELL</h4> </a> <!-- Back To Top --> <a href="#0" class="cd-top">Top</a> <!-- =-=-=-=-=-=-= JQUERY =-=-=-=-=-=-= --> <script src="js\jquery.min.js"></script> <!-- Bootstrap Core Css --> <script src="js\bootstrap.min.js"></script> <!-- Jquery Easing --> <script src="js\easing.js"></script> <!-- Menu Hover --> <script src="js\forest-megamenu.js"></script> <!-- Jquery Appear Plugin --> <script src="js\jquery.appear.min.js"></script> <!-- Numbers Animation --> <script src="js\jquery.countTo.js"></script> <!-- Jquery Smooth Scroll --> <script src="js\jquery.smoothscroll.js"></script> <!-- Jquery Select Options --> <script src="js\select2.min.js"></script> <!-- noUiSlider --> <script src="js\nouislider.all.min.js"></script> <!-- Carousel Slider --> <script src="js\carousel.min.js"></script> <script src="js\slide.js"></script> <!-- Image Loaded --> <script src="js\imagesloaded.js"></script> <script src="js\isotope.min.js"></script> <!-- CheckBoxes --> <script src="js\icheck.min.js"></script> <!-- Jquery Migration --> <script src="js\jquery-migrate.min.js"></script> <!-- Sticky Bar --> <script src="js\theia-sticky-sidebar.js"></script> <!-- Style Switcher --> <script src="js\color-switcher.js"></script> <!-- Template Core JS --> <script src="js\custom.js"></script> </body> </html>
Not sure if everything is working right because I am in the school computer and here I can not install apache / php / etc. I'm not sure about how to use cookies. Here is my code, any errors or suggestions just talk. Probably does not work, because as I said, not yet tested. login.php Code: [Select] <?php session_start(); include 'class.php'; if (isset($_POST['username']) && isset($_POST['password'])) { $user = new User($_POST['username']); if ($user->exists()) { $login = $user->login($_POST['password']); if ($login) { $_SESSION['user_id'] = $login; session_write_close(); } else { echo "Login failed."; } } else { header("Location: register.php"); } } ?> <!DOCTYPE html> <html> <head> <title>Login Form</title> </head> <body> <form action="" method="post"> <label for="username">Username: </label> <input type="text" name="username" /><br /> <label for="password">Password: </label> <input type="password" name="password" /><br /> <input type="submit" value="Submit" /> </form> </body> </html> class.php Code: [Select] <?php class User { protected $id; protected $username; protected $email; protected $sql; private $exists = FALSE; public function __construct($username) { if (empty($username)) { throw new Exception('Username cannot be blank.'); } $this->username = $username; $this->sql = new PDO(DSN, DBUSER, DBPASS); $this->exists = $this->validate(); } private function createLoginToken($id) { $token = $id . md5(microtime()); $expires = new DateTime(); $expires->add(new DateInterval('P30D')); $query = "INSERT INTO sessions (userID, token, expires) VALUES (:id, :token, :expires)"; $stmt = $this->sql->prepare($query); $stmt->execute(array(':id' => $id, ':token' => $token, ':expires' => $expires->format('Y-m-d H:i:s'))); setcookie('token', $token, $expires->getTimestamp(), '/'); } private function hashPassword($password, $salt) { $string = PASSWORD_SALT . $password . md5($salt); $hashed = crypt($string, '$2a$12$' . substr(md5($salt), 0, 22)); return $hashed; } private function validate() { $query = "SELECT COUNT(id) FROM users WHERE username = :username"; $stmt = $this->sql->prepare($query); $stmt->execute(array(':username' => $this->username)); $count = $stmt->fetchColumn(); return ($count > 0) ? TRUE : FALSE; } public function exists() { return $this->exists; } public function login($password, $remember = FALSE) { $query = "SELECT id, password, UNIX_TIMESTAMP(created) AS salt FROM users WHERE username = :username"; $stmt = $this->sql->prepare($query); $stmt->execute(array(':username' => $this->username)); $row = $stmt->fetch(PDO::FETCH_OBJ); $hashed = $this->hashPassword($password, $row->salt); if ($row->password == $hashed) { if ($remember) { $this->createLoginToken($row->id); } return $row->id; } return FALSE; } public function random() { $random = mt_random(1000,9999); return $random; } public function registerUser($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new Exception('Email does not appear to be valid.'); } $this->email = $email; $date = new DateTime(); $hashed = $this->hashPassword($pass->random(), $date->getTimestamp()); $query = "INSERT INTO users (username, password, email, created) VALUES (:username, :password, :email, :created)"; $stmt = $this->sql->prepare($query); $success = $stmt->execute(array(':username' => $this->username, ':password' => $hashed, ':email' => $email, ':created' => $date->format('Y-m-d H:i:s'))); return ($success === TRUE) ? $this->sql->lastInsertId() : FALSE; } public function verifyCookie($token) { $query = "SELECT userID FROM sessions WHERE token = :token AND expires > NOW()"; $stmt = $this->sql->prepare($query); $stmt->execute(array(':token' => $token)); return $stmt->fetchColumn(); } } ?> db.sql Code: [Select] CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) DEFAULT NULL AUTO_INCREMENT, `username` varchar(30) DEFAULT NULL, `password` varchar(60) DEFAULT NULL, `email` varchar(100) DEFAULT NULL UNIQUE, `created` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `sessions` ( `id` int(11) DEFAULT NULL AUTO_INCREMENT, `userID` int(10) DEFAULT NULL, `token` varchar(50) DEFAULT NULL, `expires` datetime DEFAULT NULL, KEY `userID` (`id`,`userID`,`token`,`expires`), KEY `token` (`id`,`userID`,`token`,`expires`), PRIMARY KEY (`id`) ) ENGINE=InnoDB; Since it appears my login system is broken i have been trying to fix it. The problem is that it isnt loggin people in. This is what im doing: The user visits login.php they enter their details and click login the posted data gets sent to login_process.php via jQuery login_process.php checks to see if the details are correct if they are it sets a cookie called uid with their user id if they clicked the remember me box then this cookie is set for a year if not then it is set as a session cookie login_process echos a success back to the jQuery in login.php when jQuery gets this success status it redirects to login_success.php the user should now be logged in. to show a logged in user i echo their username by running a query on the cookie uid but somewhere along the lines cookie uid isnt being set so the user is never logged in. here is the code:(shortened) $username = $_POST['user_name']; $password = asf_hash($_POST['password']); $remember_me = $_POST['remember_me']; //check the values with a query then: if($remember_me == 'yes' && !isset($_COOKIE['uid'])) { setcookie('uid', $_SESSION['uid'], time()+(((60*60)*24)*365)); } elseif($remember_me == 'no' && !isset($_COOKIE['uid'])) { setcookie('uid', $_SESSION['uid'], 0); } else { setcookie('uid', '', time()-3600); } login_success just contains a like to go back to the page they were originally viewing. and in my init script which is run when a page loads: $user = new user; $user->setup($_COOKIE['uid']); // this basically sets info like the username and such from a query run on the cookie. so why isnt the cookie being set? any ideas? also any ideas on making this more secure if it isnt? Thanks Heyyy, First time poster long time readerr I have a problem with my login system that i'm currently creating for a game. I've never been good with cookies so was hoping to grab some advice on this problem and anything to make my system work better with cookies . login.php ----------------------------------------- <?php ob_start(); if(isset($_COOKIE['id']) && isset($_COOKIE['password'])) { echo(" <br /> - <font color='#dddddd'>Welcome $username!</font><br /> - <a href='?x=bank'>Bank</a><br /> - <a href='?x=levelup'>Level Up</a><br /> - <a href='?x=members&r=edit'>Edit Profile</a><br /> - <a href='?x=members'>Member List</a><br /> - <a href='?x=logout'>Logout</a><br /> <br /> "); if($_POST['login']) { $username = safe($_POST['username']); $password = safe(md5($_POST['password'])); $check = mysql_query("SELECT * FROM `users` WHERE username='$username'") or die(mysql_error()); $info = mysql_fetch_array($check) or die(mysql_error()); if(mysql_num_rows($check) == 1 && $pass == $info['password']) { setcookie(id, $info['id'], time() + 3600, "/"); setcookie(password, $password, time() + 3600, "/"); echo("<meta http-equiv='refresh' content='4;url=http://www.simplydollclothes.com/matty/index.php'>"); echo("You have successfully logged in!"); } } else { echo(" <form name='login' method='POST'> <table width='100%'> <tr> <td width='25%'><font color='#dddddd'>Username</font></td> <td width='75%'><input type='text' name='username' size='17' /></td> </tr> <tr> <td width='25%'><font color='#dddddd'>Password</font></td> <td width='75%'><input type='password' name='password' size='17' /></td> </tr> <tr> <td width='25%'><input type='submit' name='login' value='Login' /></td> <td width='75%'><a href='?x=forgotpass'>Forgot password?</a> <a href='?x=register'>Register</a></td> </tr> </table> </form> "); } } ?> After pressing login the page just refreshes lightning fast and no cookies are set. Any help will be much appreciated hi i need help an idea how can i separate members from admins since i dont know how to create login form i used tutorial ( http://www.youtube.com/watch?v=4oSCuEtxRK8 ) (its session login form only that i made it work other tutorials wre too old or something) how what i want to do is separate members and admins because admin need more rights to do now i have idea but dont know will it work like that what i want to do is create additional row in table named it flag and create 0 (inactive user) 1 (member) 2 (admin) will that work? and how can i create different navigation bars for users and admins? do you recommend that i use different folders to create it or just script based on session and flag? Hello guys, Is there on web any updated tutorial on how can I add Facebook login on my simple php login script? Hi guys. What I want to create is really complicated. Well I have a login system that works with post on an external website. I have my own website, but they do not give me access to the database for security reasons, therefore I have to use their login system to verify my users. What their website does is that it has a post, with username and password. The POST website is lets say "https://www.example.com/login". If login is achieved (i.e. username and password are correct), it will redirect me to "https://www.example.com/login/success" else it will redirect me to "https://www.example.com/login/retry". So I want a PHP script that will do that post, and then according to the redirected website address it will return me TRUE for success, FALSE for not successful login. Any idea?? Thanks Hi guys, Can anyone assist me. I am trying to create a login for admin and user (if user not a member click register link) below is my code: But whenever I enter the value as: Username: admin Password:123 - I got an error message "That user does not exist!" Any suggestion and help would be appreciated. Thanks. login.php <?php //Assigned varibale $error_msg as empty //$error_msg = ""; session_start(); $error_msg = ""; if (isset($_POST['submit'])) { if ($a_username = "admin" && $a_password = "123") { //Define $_POST from form text feilds $username = $_POST['username']; $password = $_POST['password']; //Add some stripslashes $username = stripslashes($username); $password = stripslashes($password); //Check if usernmae and password is good, if it is it will start session if ($username == $a_username && $password == $a_password) { session_start(); $_SESSION['session_logged'] = 'true'; $_SESSION['session_username'] = $username; //Redirect to admin page header("Location: admin_area.php"); } } $username = (isset($_POST['username'])) ? $_POST['username'] : ''; $password = (isset($_POST['password'])) ? $_POST['password'] : ''; if($username && $password) { $connect = mysql_connect("localhost", "root", "") or die ("Couldn't connect!"); mysql_select_db("friendsdb") or die ("Couldn't find the DB"); $query = mysql_query ("SELECT * FROM `user` WHERE username = '$username'"); $numrows = mysql_num_rows($query); if ($numrows != 0){ while ($row = mysql_fetch_array($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //Check to see if they are match! if ($username == $dbusername && md5($password) == $dbpassword) { header ("Location: user_area.php"); $_SESSION['username'] = $username; } else $error_msg = "Incorrect password!"; //code of login }else $error_msg = "That user does not exist!"; //echo $numrows; } else $error_msg = "Please enter a username and password!"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login Page</title> </head> <body> <br /> <?php require "header.php"; ?><br /> <div align="center"> <table width="200" border="1"> <?php // If $error_msg not equal to emtpy then display error message if($error_msg!="") echo "<div id=\"error_message\"style=\"color:red; \">$error_msg</div><br />";?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <!--form action="login_a.php" method="post"--> Username: <input type="text" name="username" /><br /><br /> Password: <input type="password" name="password" /><br /><br /> <input type="submit" name = "submit" value="Log in" /> </form> <p> </p> Register a <a href="register.php">New User</a> </table> </div> </body> </html> How to add the ability to login with username or email for login?
<?php ob_start(); include('../header.php'); include_once("../db_connect.php"); session_start(); if(isset($_SESSION['user_id'])!="") { header("Location: ../dashboard"); } if (isset($_POST['login'])) { $email = mysqli_real_escape_string($conn, $_POST['email']); $password = mysqli_real_escape_string($conn, $_POST['password']); $result = mysqli_query($conn, "SELECT * FROM users WHERE email = '" . $email. "' and pass = '" . md5($password). "'"); if ($row = mysqli_fetch_array($result)) { $_SESSION['user_id'] = $row['uid']; $_SESSION['user_name'] = $row['user']; $_SESSION['user_email'] = $row['email']; header("Location: ../dashboard"); } else { $error_message = "Incorrect Email or Password!!!"; } } ?>
Hi everyone i wonder if you can help me he I need a script for a login and check login- create cookie. Here is my form: <form method="post" action="check_login.php"> <p> <input type="submit" name="Submit2" value="go" /> </fieldset> </p> </form> that sends it to check_login (which BEFORE i deleted something by accident, used to take me to a username and password box) But now all it does is send me straight to the memebrs area??? Can i change the check_login.php script to make it work correctly: Code: [Select] <?php // Connects to your Database mysql_connect("server", "user", "password") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['upassword']) { } else { header("Location: members_area.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['upassword']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['upassword'] = stripslashes($_POST['upassword']); $info['upassword'] = stripslashes($info['upassword']); $_POST['upassword'] = md5($_POST['upassword']); //gives error if the password is wrong if ($_POST['upassword'] != $info['upassword']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['upassword'], $hour); //then redirect them to the members area header("Location: members_area.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width="316" height="120" border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="upassword" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> Hello, I am once again desperately asking for your help, I am working on a simple login page and I am having trouble actually getting it to login. I display error messages for if the user doesn't enter anything but I can't seem to get it to work for if the credentials are wrong. It logs the user in whether the information is right or not and i dont even know what to do now
This is the code any suggestions would be greatly appreciated <?php /* Name: Deanna Slotegraaf Course Code: WEBD3201 Date: 2020-09-22 */ $file = "sign-in.php"; $date = "2020-09-22"; $title = "WEBD3201 Login Page"; $description = "This page was created for WEBD3201 as a login page for a real estate website"; $banner = "Login Page"; require 'header.php'; $error = ""; if($_SERVER["REQUEST_METHOD"] == "GET") { $username = ""; $password = ""; $lastaccess = ""; $error = ""; $result = ""; $validUser = ""; } else if($_SERVER["REQUEST_METHOD"] == "POST") { $conn; $username = trim($_POST['username']); //Remove trailing white space $password = trim($_POST['password']); //Remove trailing white space if (!isset($username) || $username == "") { $error .= "<br/>Username is required"; } if (!isset($password) || $password == ""){ $error .= "<br/>Password is required"; } if ($error == "") { $password = md5($password); $query = "SELECT * FROM users WHERE EmailAddress='$username' AND Password='$password'"; $results = pg_query($conn, $query); //$_SESSION['username'] = $username; //$_SESSION['success'] = "You are now logged in"; header('location: dashboard.php'); }else { $error .= "Username and/or Password is incorrect"; } } ?> <div class = "form-signin"> <?php echo "<h2 style='color:red; font-size:20px'>".$error."</h2>"; ?> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label for="uname"><b>Login ID</b></label> <input type="text" name="username" value="<?php echo $username; ?>"/> <br/> <label for="psw"><b>Password</b></label> <input type="password" name="password" value="<?php echo $password; ?>"/> <br/> <button type="submit" name="login_user">Login</button> <button type="reset">Reset</button></div> </form> </div> <?php require "footer.php"; ?>
The code below is the only part of my script failing and I have no clue why. I even tried setting the TestCookie for 352 days. What boggles my mind is that this code used to work and is now failing. Has something changed? $value = "wtf"; setcookie("TestCookie",$value, time()+3600*24); setcookie("user", $name1, time()+14400); setcookie("userid", $uid1, time()+14400); setcookie("coid", $coid1, time()+14400); setcookie("login", "yes", time()+14400); setcookie("status", $status1, time()+14400); I'm trying to write a script that allows the user to select their personal settings for the site. They can pick the color of their background, link color, link hover color and the header color. the first file is supposed to use the defaults, blue for the links, orange for the link hover color red for the background and blue for the header. the second file is supposed to configure the cookie variables to store the values entered by the user and the third file i'm supposed to modify the internal stylesheet to utilize the values stored in the session variables. I tried to set each of the values in file two but i think i messed it up. I dont know how to modify the stylesheet to accept and change to the values of the cookies...Please help here are the files file1.php Code: [Select] <?php //Handle the form if it has been submitted: if (isset($_POST['background_color'], $_POST['link_color'], $_POST['link_hover_color'], $_POST['header_color'])){ //send the cookies: setcookie('background_color', $_POST['background_color'], time()+10000000); setcookie('link_color', $_POST['link_color'], time()+10000000); setcookie('link_hover_color', $_POST['link_hover_color'], time()+10000000); setcookie('header_color', $_POST['header_color'], time()=10000000); //Message to be printed later: $msg = '<p>Your settings have been entered! Click <a href="file2.php">here</a> to see them in action.</p>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>File1</title> <style type="text/css"> <!-- These are the styles the session (if it exists) should configure --> a:link {color:blue;} a:hover {color:orange;} body {background-color:red} h1 {color:blue; text-align:center;} </style> </head> <body> <?php //if the cookies were sent print a message if (isset($msg)){ print $msg; } ?> <div><p>Please complete this form to configure the appearance of this website:</p> <form action="File2.php" method="post"> <select name="background_color"> <option value="">Background Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="link_color"> <option value="">Link Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="link_hover_color"> <option value="">Link Hover Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="header_color"> <option value="">Header Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <input type="submit" name="submit" value="Configure!" /> </form> </div> </body> </html> file2.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>File2</title> </head> <body> <div> <?php include('file1.php'); //check for a background color if (isset($_COOKIE['background_color'])){ print "\body: #" . htmlentities($_COOKIE['background_color']) . ";\n"; }else{ print "\body: #c00"; } //check for a link_color if (isset($_COOKIE['link_color'])){ print "\a:link: #" . htmlentities($_COOKIE['link_color']) . ";\n"; }else{ print "\a:link: #00f"; } //check for a link_hover color: if (isset($_COOKIE['link_hover_color'])){ print "a\:hover: #" . htmlentities($_COOKIE['link_hover_color']) . ";\n"; } //Check for a header color if (isset($_COOKIE['header_color'])){ print "\h1: #" . htmlentities($_COOKIE['header_color']). ";\n"; } ?> Your settings have been updated. <a href="File3.php">Click here</a> to continue. <br /><br /> </div> </body> </html> file3.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>File3</title> <style type="text/css"> <!-- These are the styles the session should configure --> a:link {color:blue;} a:hover {color:orange;} body {background-color:red} h1 {color:blue; text-align:center;} </style> </head> <body> <div> <h1>Welcome to YOUR pretty website</h1> <a href = "File1.php">Click here</a> to go back and start over!</a> </div> </body> </html> I'm pretty sure i did in file2 what i was supposed to do in file3 im totally confused Hi guys, I am having a sticky problem with Cookies. Basically, I've had to change the settings of my CMS which has resulted in me now having the same cookie names for the cookie domains .domain.com and www.domain.com. I know I can just clear my cookies and the problem will be sorted, but it's not feasible for me to expect users of my site to clear their cookies. So my question is this. How can I delete the cookies created using www.domain.com with PHP? Everytime I set the expiry date of the cookies, it only applies it to those on .domain.com. Any help would be gratefully appreciated!! This is prob a stupid question.. but i've always wondered..
When deleting a cookie why do we use
why do we use:
setcookie($name, '', time() - 3600, "/", "", 0);
when this works just fine:
setcookie($name, '', 0, "/", "", 0);
isn't the time() just a waste of space?
I ask this because everywhere i look i see:
setcookie($name, '', time() -3600 , "/", "", 0);
hello; it seems strange that php can set cookies, since php is on the serer-side, but the cookies are on the client-side ... is there something that I am missing? I have this page where I create two cookies with the username and passwords of the users for the website. Code: [Select] $equipa = $_POST['equipa'] ; $pass = $_POST['codigo'] ; setcookie("equipa", "$equipa", time() + 3600) ; setcookie("codigo", "$pass", time() + 3600) ; In the next page, I can have access to the cookie, with this script : Code: [Select] <?php $equipa = $_COOKIE['equipa'] ; echo $equipa ; $pass = $_COOKIE['codigo'] ; echo $pass ; ?> But in this page you have to fill a form and send it, going to a new page. In this new one, with the exact same code, I can't access the cookie. If anyone could please help me and tell me why..... Thanks for the help Okay im having a problem with cookies so if anyone can help i would be grateful. When you login you can choose how long to stay in for. For testing purposes the choices a Forever 1 Hour 1 Day Never Based on your choice i am setting the cookie expiration as follows: if ($_POST['remember_me'] == '1') { setcookie('remember', time() + 99999999999999); } elseif ($_POST['remember_me'] == '3600') { setcookie('remember', time() + 3600); } elseif ($_POST['remember_me'] == '84600') { setcookie('remember', time() + 84600); } elseif ($_POST['remember_me'] == '0') { setcookie('remember'); } echo $_COOKIE['remember']; } Then for testing I am echoing the cookie at the head of the document: echo "Cookie: " . @$_COOKIE['remember']; The problem is that when the browser is closed the cookie is gone. Only the last option "never" is set as a session cookie which means the others should stay active even when the browser is closed shouldnt they? Anything i have missed here? Hey all, http://www.adamrowden.co.uk/photo-searchr.asp If you visit this link, you'll see on the left side you have a few photos. If you click a photo from that page and then go back to the link i've provided you'll see that it shows you your 'recently viewed photos'. I'm wanting to do exactly that and need some pointers on how i would!? I'd be very grateful for any help Thanks, Jimmy m Hello all, I hope someone can shed some light/point me in the right direction. I have a site that allows you to search for a customer then view and change their detail. page 1 has a search box for name entry. page 2 displays all the matches retrieved from a db table that match. The user selects which customer is the correct 1 and sets a cookie containing the selected customers unique id. page 3 allows changing of the customers details. now the problem I have: If a user navigates to page 3 and has a customers details on page for viewing all is well. If they open a new tab (leaving page 3 open on first tab) and go to page 1, search for another customer, page 2 select another customer (which overwrites cookie) then to page 3. They now have two tabs open on page 3 both displaying different customer details. If they return to the first tab and change some detail, when they save it actually updates the users details that corrispond to the second tab. I know this is because the cookie has been changed that holds the unique id that is required for the update query. How can I prevent this? I've looked at sessions but it would seem the same issue would excist. Am I wrong? Many Thanks I hope I made sense. |