Hi Brad,
Many thanks for your reply.
The scripts in my post are ones I am using to try and get my head around the workings of cookies.
The actual scripts I am trying to get working are more complexed This is what I am trying to do.
This is a set of scripts that deal with a subscription service which offer a free trial and I am trying to detect if the same device is trying to subscribe again to the trial after it expires.
I have a script that sets a cookie by a script "root/activate/process.php", this script uses some variables from a user input form. All this works fine.
The problem I have is the agent.php script will not read the cookie. I have check that the cookie is on the PC I am using to construct the script.
I know that at this moment in time the scripts are a wee bit messy.
require_once('../Connections/flightq.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_fidsUser = "-1";
if (isset($_POST['login'])) {
$colname_fidsUser = $_POST['login'];
}
mysql_select_db($database_flightq, $flightq);
$query_fidsUser = sprintf("SELECT member_id, login, pass, licensed FROM FIDS_members WHERE login = %s", GetSQLValueString($colname_fidsUser, "text"));
$fidsUser = mysql_query($query_fidsUser, $flightq) or die(mysql_error());
$row_fidsUser = mysql_fetch_assoc($fidsUser);
$totalRows_fidsUser = mysql_num_rows($fidsUser);
if($row_fidsUser['licensed']!= "1"){
$username = $row_fidsUser['login']; // Gets the inputted username from the form
$password = $row_fidsUser['pass']; // Gets the inputted password from the form
$time = time(); // Gets the current server time
$_SESSION['username'] = $username;
mysql_select_db($database_flightq, $flightq);
$query_fids = "SELECT member_id, login, pass FROM FIDS_members WHERE login = '$username' AND pass = '$password'";
$fids = mysql_query($query_fids, $flightq) or die(mysql_error());
$row_fids = mysql_fetch_assoc($fids);
$memberid = $row_fids['member_id'];
if(mysql_num_rows($fids)) { // If the username and password are correct do the following;
$_SESSION['loggedin'] = 1; // Sets the session 'loggedin' to 1
// Check to see if the 'setcookie' box was ticked to remember the user
setcookie('License', $username,$time +60*60*24*365*10, "/flightcentretrial/"); // Sets the cookie
$updateSQL = sprintf("UPDATE FIDS_members SET licensed=%s WHERE member_id=%s",
GetSQLValueString($_POST['licensed'] = 1, "text"),
GetSQLValueString($_POST['member'] = $row_fids['member_id'] , "int"));
mysql_select_db($database_flightq, $flightq);
$Result1 = mysql_query($updateSQL, $flightq) or die(mysql_error());
}
if($_SESSION['iPhone'] == 1) {
header('Location: iphone_complete.php');
exit();
} elseif($_SESSION['iPad'] == 1) {
header('Location: ipad_complete.php');
exit();
} elseif($_SESSION['Blackberry'] == 1) {
header('Location: 480_360_complete.php');
exit();
} else {
header('Location: activation_complete.php');
exit();
}
} else {
header('Location: activation_error.php');
exit();
}
mysql_free_result($fidsUser);
I have a script that detects if the users browser has cookies enabled.
This script is in the root and works as expected.
setcookie('test', 1, time()+3600);
if(!isset($_GET['cookies'])){
header('Location: detectcookie.php?cookies=true');
}
if(count($_COOKIE > 0)){
header('Location: activate/agent.php');
} else {
header('Location: cookies.php');
If the browser has cookies enabled the above script calls: root/activate/agent.php
agent.php should look to see if the cookie "License" is set, and if true call root/activate/lic_error.php
agent.php
if(isset($_COOKIE["License"])){
header ("location: activate/lic_error.php");
}else{
// continue processing
}
Sorry for such a long post but any help you could give would be great.