Jump to content

[SOLVED] Setting a permanant cookie


graham23s

Recommended Posts

Hi Guys,

 

what im trying to do here is set a permanant cookie (which contains a time stamp) on 1 of my pages so i can track the users last visit, 

 

i have included a seperate file on this page called timestamp.php my question is how would i go about setting this cookie in the timestamp.php

 

i set my main one using:

 

<?php
     include("includes/db_connection.php");
     include("includes/constants.php");
     
 $username = trim(strtolower(mysql_real_escape_string($_POST['username'])));
 $password = trim(strtolower(mysql_real_escape_string($_POST['password'])));	

  	 if (empty($username) || empty($password)) {	
  	 
 echo "Please fill in both fields.";
 exit;	

 }	

 ## check the user is in the database ###############################################
 $login_query = "SELECT username,password FROM `membership` WHERE `username`='$username' AND `password`='$password'";
 $login_result = mysql_query($login_query) or die (mysql_error());

 $is_greater_than_1 = mysql_num_rows($login_result);

 // was there a user found?...#######################################################
 if($is_greater_than_1 != 1) {	

     echo "Sorry username and password combination not found.";
     exit;	
     
 } else {	

 ## User is logged in so Let's give him a cookie. ###################################
 setcookie ("member",$username,time()+1957240,"/"); 

 ## a variable to hold the cookie ###################################################
 $member = $username;

 ## If cookie failed set a session...################################################
 $_SESSION['member'] = 'member';	

 ## Update Login timer...############################################################
 $timer_query = "UPDATE `membership` SET `login`=now() WHERE `username`='$username' AND `password`='$password'";
 $timer_result = mysql_query($timer_query) or die (mysql_error());

     if ($timer_result) {	
     
 header("Location:my_account.php"); 

     } 
         
     } 
?>

 

would i just do:

 

setcookie ("member",$username,time()+1957240,"/"); 

 

that type of code alone nothing else? also how would i make it do a timestamp at all?

 

thanks for any help guys

 

Graham

Link to comment
Share on other sites

Hi Mate,

 

by doin a bit more digging it's probably best just to set a cookie that expires way in the future instead, but i'm not sure exactly when to set this, should i do it in my original

 

login_check.php

 

form and redirect the header to the page?

 

cheers

 

Graham

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.