i have included my page script i am a bit stumped at which way to approach this as the two methods i thought would work do not.
basically i am usinig some if then statements to check against a database to determine if a value has been set. if that value has not been set i present a link to the user which when clicked stores the reuired info and moves them on to the next page. the storing and presenting of the approriate link works fine, if for example the db lookup indicates that a value has been set a differnt set of information is presented with a different link
i have tried redirecting by setting the headers but of course there has already been output so i get the usual error, i have tried using the ob_start() functions but i dont think i know the right place to put them.
any direction would be greatly appreciates as well as any optimizing suggestions for the current scripts
here it is:
<?php require_once('../Connections/vemicsConn.php'); ?>
<?php
$colname_userconn = "1";
if (isset($HTTP_COOKIE_VARS['user_name'])) {
$colname_userconn = (get_magic_quotes_gpc()) ? $HTTP_COOKIE_VARS['user_name'] : addslashes($HTTP_COOKIE_VARS['user_name']);
}
mysql_select_db($database_vemicsConn, $vemicsConn);
$query_userconn = sprintf("SELECT * FROM login_info WHERE user_name = '%s'", $colname_userconn);
$userconn = mysql_query($query_userconn, $vemicsConn) or die(mysql_error());
$row_userconn = mysql_fetch_assoc($userconn);
$totalRows_userconn = mysql_num_rows($userconn);
?>
<?php
// countdown function
// parameters: (year, month, day, hour, minute)
//--------------------------
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
function countdown($year, $month, $day, $hour, $minute)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left606024)/60/60);
$minutes_left = floor(($difference - $days_left606024 - $hours_left6060)/60);
// OUTPUT
//g:i ag:i a.$hours_left." hours ".$minutes_left." minutes left"
echo "<p align='center' class='regtext'>Today's date ".date("F j, Y")."<br/>";
echo "<p align='center' class='regtext'>Expiration date ".date("F j, Y",$the_countdown_date)."</p><br/>";
echo "<p align='center' class='regtext'>Countdown ".$days_left." days remain.";
//if 0 days then expired message etc goes here
}
?>
<?php function parse_str_ext($toparse) {
$returnarray = array();
$keyvaluepairs = split("&", $toparse);
foreach($keyvaluepairs as $pairval) {
$splitpair = split("=", $pairval);
if(!array_key_exists($splitpair[0], $returnarray)) $returnarray[$splitpair[0]] = array();
$returnarray[$splitpair[0]][] = $splitpair[1];
}
return $returnarray;
}?>
<?php
if(isset($_REQUEST['store_the_enddate'])){
//stuff to set
//echo date(n);
$month = date(n) + 1;
if($month > 12){
$month = 1;
}
//add digit if necc
if($month < 10){
$month = "0".$month;
}
$year = date(Y);
$day= date(d);
$hour= date(h);
$minute= date(i);
//create the end date
//still need to do some advanced day checking to assure month has the day ie 31 etc
$thefinal = $year."-".$month."-".$day." ".$hour.":".$minute.":00";
//echo $thefinal;
//put it in the db
mysql_select_db($database_vemicsConn, $vemicsConn)
or die("Couldn't open $db: ".mysql_error());
mysql_query ("UPDATE login_info SET course_end_date = '$thefinal' WHERE user_name = '$HTTP_COOKIE_VARS[user_name]'");
//mysql_close($vemicsConn);
$month = date(m);
$year = date(Y);
$day= date(d);
$hour= date(h);
$minute= date(i);
$thefinal = $year."-".$month."-".$day." ".$hour.":".$minute.":00";
//mysql_select_db($database_vemicsConn, $vemicsConn)
//or die("Couldn't open $db: ".mysql_error());
mysql_query ("UPDATE login_info SET course_start_date = '$thefinal' WHERE user_name = '$HTTP_COOKIE_VARS[user_name]'");
mysql_close($vemicsConn);
//ob_end_flush();
//$location = $row_userconn[current_course];
//echo $location;
//header("Location: $location");
//exit();
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="sitestyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<p align="center" class="regtext">course splash page</p>
<p align="center" class="regtext">welcome <?php echo $row_userconn['first_name']; ?> <?php echo $row_userconn['last_name']; ?> </p>
<?php
// if then to determine if user has set a start daye
if($row_userconn['course_start_date'] == "0000-00-00 00:00:00"){
//has not started course yet
echo "<p align='center' class='regtext'>this is your first visit your time will start once you click the link below</p>";
//set_the_end_date();
} else {
// display current countdown
echo "<p align='center' class='regtext'>you've started the course:</p>";
$mystr=$row_userconn['course_end_date'];
$myarray = explode(" ", $mystr);
$mydate = $myarray[0];
$mytime = $myarray[1];
$mydate = explode("-", $mydate);
$mytime = explode(":", $mytime);
$year = $mydate[0];
$month= $mydate[1];
$day= $mydate[2];
$hour= $mytime[0];
$minute= $mytime[1];
//sendfunction
countdown($year, $month, $day, $hour, $minute);
}
//if($row_userconn['course_end_date'] == "0000-00-00 00:00:00"){
?>
<p align="center"> </p>
<?php if($row_userconn['course_start_date'] == "0000-00-00 00:00:00"){
?><p align="center"><a href=<?php echo $row_userconn['current_course'] ?>"<?php echo $SERVER['PHP_SELF']?>?store_the_enddate=1">store</a></p>
<?php }else{
?><p align="center"><a href=<?php echo $row_userconn['current_course'] ?> target="self" class="regtext">been here</a></p>
<?php }?>
</body>
</html>
<?php
mysql_free_result($userconn);
?>