Jeg har en konkurrence hvor der skal en cookie i
jeg har en konkurrence hvor man selvfølgelig ikke skal kunne deltage flere gange, så derfor har jeg prøvet at sætte en cookie i den, men synes ikke det virker!! Er der nogen der kan hjælpeHer er de "cookie" ting jeg har brugt:
SetCookie ("konkurrence", "ja", time() + 3600 * 24 * 14); // sætter cookie i 14 dage.
<?php
if ($HTTP_COOKIE_VARS["konkurrence"] != "ja") {
?>
<!-- VIS KONKURRENCE -->
<?php
} else {
?>
<!-- BRUGEREN HAR STEMT -->
<?
echo "Du har allerede stemt og det er kun muligt at stemme én gang";
}
?>
_______________________________________
Og her er selve koden!:
Håber der er nogen der kan hjælpe!
<?
######################################################################################################
#
# Main File. Feedback Mailer. v 1.01
#
######################################################################################################
#
# Author: hpnadig
# Last modified on Jan 2004.
#
# copyright 2004, hpnadig. http://hpnadig.com/index.php?pg=scripts
#
# You can use, redistribute the script provided that the author name and credits are maintained
# intact. If you make any changes, I'd be glad if you can inform me about that... and I'll include
# it in the next version of the script with, ofcourse, due credits. So, please do inform me at
# hpnadig@gmail.com,
# along with the diff.
#
# modified by donie
# addition : cookies for form values, website field, easy to integrate with website, and valid XHTML 1.0 trans
#
######################################################################################################
# version 1.01
# CONFIGURATION
# Subject prefix for the mail arriving in your Mail Box... eg. [hpnadig.com-feedback]
$sub = 'Mail fra Metro Musik Emne: ';
# The Mail address you want the mail to be sent to...
$address = 'mail adressen';
# The Mail address(es) you want to be included in the BCC list...
$ccmail = ''; // $ccmail = ''; if you dont want use CC
# The Mail address(es) you want to be included in the BCC list...
$bccmail = ''; // $bccmail = ''; if you dont want use BCC
# Error Messages... edit them to your needs :)
$errors['name'] = "Intet Fornavn indtastet";
$errors['eftername'] = "Intet Efternavn indtastet!";
$errors['adresse'] = "Ingen Adresse indtastet!";
$errors['postnr'] = "Intet Post nr. indtastet!";
$errors['by'] = "Ingen By indtastet!";
$errors['fdato'] = "Ingen Fødselsdato indtastet!";
$errors['email'] = "Indtast korrekt E-mail!";
$errors['tlf'] = "Indtast dit korrekt Telefonnummer!";
$errors['subject_pre'] = "Du skal svare på spørgsmål 1";
$errors['subject_pre2'] = "Du skal svare på spørgsmål 2";
# error reporting, and misscellany__________________________________________________________ #
# input value cookies
if($submit) {
SetCookie ("namec", $name, time()+2592000);
SetCookie ("efternamec", $eftername, time()+2592000);
SetCookie ("adressec", $adresse, time()+2592000);
SetCookie ("postnrc", $postnr, time()+2592000);
SetCookie ("byc", $by, time()+2592000);
SetCookie ("emailc", $replyemail, time()+2592000);
SetCookie ("tlfc", $tlf, time()+2592000);
SetCookie ("subject_prec", $subject_pre, time()+2592000);
SetCookie ("subject_pre2c", $subject_pre2, time()+2592000);
$namec = $name;
$efternamec = $eftername;
$adressec = $adresse;
$postnrc = $postnr;
$byc = $by;
$emailc = $replyemail;
$tlfc = $tlf;
$tlfc = $subject_pre;
$tlfc = $subject_pre2;
SetCookie ("namec", $name, time());
SetCookie ("efternamec", $eftername, time());
SetCookie ("adressec", $adresse, time());
SetCookie ("postnrc", $postnr, time());
SetCookie ("byc", $by, time());
SetCookie ("emailc", $replyemail, time());
SetCookie ("tlfc", $tlf, time());
SetCookie ("subject_prec", $subject_pre, time());
SetCookie ("subject_prec2", $subject_pre2, time());
}
if($formsent) {
SetCookie ("konkurrence", "ja", time() + 3600 * 24 * 14); // sætter cookie i 14 dage.
}
?>
<?php
if ($HTTP_COOKIE_VARS["konkurrence"] != "ja") {
?>
<!-- VIS KONKURRENCE -->
<?php
# Error Reporting...
error_reporting(E_NONE);
# Displays the appropriate error message...
function display_error($form_element){
echo " <div align=\"center\" style=\"padding: 0px;\"><b><font color=\"#F2f2f2\">" .$form_element ."</font></b><br /></div><div align=\"center\" style=\"border-bottom: 1px solid #CCC;\"><br /></div>";
}
# Checks for a valid mail address...
function do_check_email($address) {
return preg_match('/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/',$address);
}
# Checks for a valid post nummer...
function do_check_postnr($postnr) {
return eregi('^[0-9]{4,4}$',$postnr);
}
# Checks for a valid post Fødselsdato...
function do_check_fdato($fdato) {
return eregi('^[0-9-]{6,10}$',$fdato);
}
# Checks for a valid post telefon...
function do_check_tlf($tlf) {
return eregi('^[+0-9]{8,11}$',$tlf);
}
?>
<!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" dir="ltr" lang="en">
<head>
<title><?php echo("$title"); ?></title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<link REL="STYLESHEET" type="text/css" HREF="../../style.css">
</head>
<body bgcolor="#000000" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<div align="center">
<div id="outerbox">
<div id="innerbox">
<?php
// Check for the fields.. yet to be customized.....
if($_POST['done'] == "yes"){
$flag = 1;
if(!($_POST['name']) && $flag){
display_error($errors['name']);
$flag = 0;
}
if(!($_POST['eftername']) && $flag){
display_error($errors['eftername']);
$flag = 0;
}
if(!($_POST['adresse']) && $flag){
display_error($errors['adresse']);
$flag = 0;
}
if(!do_check_postnr($_POST['postnr']) && $flag){
display_error($errors['postnr']);
$flag = 0;
}
if(!($_POST['by']) && $flag){
display_error($errors['by']);
$flag = 0;
}
if(!do_check_email($_POST['replyemail']) && $flag) {
display_error($errors['email']);
$flag = 0;
}
if(!($_POST['subject_pre']) && $flag){
display_error($errors['subject_pre']);
$flag = 0;
}
if(!($_POST['subject_pre2']) && $flag){
display_error($errors['subject_pre2']);
$flag = 0;
}
if(!do_check_tlf($_POST['tlf']) && $flag){
display_error($errors['tlf']);
$flag = 0;
}
if ($flag == 1) {
$name = $_POST['name'];
$eftername = $_POST['eftername'];
$adresse = $_POST['adresse'];
$postnr = $_POST['postnr'];
$by = $_POST['by'];
$replyemail = $_POST['replyemail'];
$tlf = $_POST['tlf'];
$subject_pre = $_POST['subject_pre'];
$subject_pre2 = $_POST['subject_pre2'];
$extra_hdr_str = "From: $name <$replyemail> \r\ncc: $ccmail \r\nbcc: $bccmail \r\nContent-type: text/html\r\nX-Mailer: PHP/" .phpversion();
$date = strftime('Den %D - klokken %T ');
// if there is no 'http://' on website field
if ( substr ($website, 0, 7) != "http://") {
$url = "http://" . $website;
}
else {
$url = $website;
} // done!
$body = "<p align='left'> $date <br /><br /> Navn: $name <br /> Efternavn: $eftername <br /><br /> Adresse: $adresse <br /> Post nr.: $postnr <br /> By: $by <br /><br /> Email: $replyemail <br /> Telefon: $tlf <br /><br />
<br /><br /> Svar1: $subject_pre <br /><br /> Svar2: $subject_pre2 <br /><br />IP address: $REMOTE_ADDR</p>";
if($done == "yes")
{
$formsent = mail($address,$sub,$body,$extra_hdr_str); // BUILT IN PHP FUNCTION mail() TO SENT EMAIL
if($formsent) { echo ("<div align=\"center\" style=\"padding: 0px;\"><font color=\"#FFFFFF\">Tak <b>$name</b> fordi du gerne vil være medlem af vores musikforening og støtte os!<br /> Meddelsen er blevet sendt.</font><br /></div><div align=\"center\" style=\"border-bottom: 1px solid #CCC;\"><br /></div>"); }
else { echo ("<div align=\"center\" style=\"padding: 0px;\"><font color=\"#FFFFFF\">Desværre skete der en fejl <b>$name</b>, hvilket betyder at meddelsen ikke blev sendt!</b>. Prøv igen... </font><br /></div><div align=\"center\" style=\"border-bottom: 1px solid #CCC;\"><br /></div>"); }
}
}
}
// end of checking
?>
<br />
<?php
if(!$formsent) { // if the email has not been sent, will display message above and form below
?>
<div id="form" align="left" style="width: 325px; height: 477px">
<form action="<?php echo "$PHP_SELF" ?>" method="post">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="98%"><font color="#FFFFFF"><b>Hvad koster det at blive medlem
af metromusik?</b></font><p style="margin-top: -6px; margin-bottom: 0">
<font color="#FFFFFF"><br />
<input type="radio" name="subject_pre" value="50 kr" /> 50 kr.<br />
<input type="radio" name="subject_pre" value="100 kr" /> 100 kr.<br />
<input type="radio" name="subject_pre" value="150 kr" /> 150 kr. </font></td>
<td width="2%"> </td>
</tr>
<tr>
<td width="98%"> </td>
<td width="2%"> </td>
</tr>
<tr>
<td width="98%"><font color="#FFFFFF"><b>Hvornår udkom bandet VETO
debutalbum?</b></font><p style="margin-top: -6px; margin-bottom: 0">
<font color="#FFFFFF"><br />
<input type="radio" name="subject_pre2" value="12 februar" /> 12</font><font color="#ffffff">.
februar</font><font color="#FFFFFF"> <br />
<input type="radio" name="subject_pre2" value="27 februar" /> </font>
<font color="#ffffff">27. februar</font><font color="#FFFFFF"> <br />
<input type="radio" name="subject_pre2" value="23 marts" /> 23</font><font color="#ffffff">.
marts </font><font color="#FFFFFF"> </font></td>
<td width="2%"> </td>
</tr>
<tr>
<td width="98%"> </td>
<td width="2%"> </td>
</tr>
<tr>
<td width="98%"> </td>
<td width="2%"> </td>
</tr>
<tr>
<td width="98%">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="11"> </td>
<td width="118"><font color="#FFFFFF">
<b>Fornavn</b>*</font></td>
<td><font color="#FFFFFF">
<input class="input" type="text" name="name" size="20" value="<?php echo "$namec"; ?>" /></font></td>
</tr>
<tr>
<td width="11"> </td>
<td width="118"><font color="#FFFFFF">
<b>Efternavne</b>*</font></td>
<td><font color="#FFFFFF">
<input class="input" type="text" name="eftername" size="20" value="<?php echo "$efternamec"; ?>" /></font></td>
</tr>
<tr>
<td width="11"> </td>
<td width="118"><font color="#FFFFFF">
<b>Adresse</b>*</font></td>
<td><font color="#FFFFFF">
<input class="input" type="text" name="adresse" size="20" value="<?php echo "$adressec"; ?>" /></font></td>
</tr>
<tr>
<td width="11">
</td>
<td width="118">
<b><font color="#FFFFFF">Post nr.* </font></b></td>
<td><font color="#FFFFFF">
<input class="input" type="text" name="postnr" size="7" value="<?php echo "$postnrc"; ?>" /></font></td>
</tr>
<tr>
<td width="11"> </td>
<td width="118"><font color="#FFFFFF"><b>By</b>*</font></td>
<td><font color="#FFFFFF">
<input class="input" type="text" name="by" size="20" value="<?php echo "$byc"; ?>" /></font></td>
</tr>
<tr>
<td width="11"> </td>
<td width="118"><font color="#FFFFFF">
<b>E-mail</b>*</font></td>
<td><font color="#FFFFFF">
<input class="input" type="text" name="replyemail" size="20" value="<?php echo "$emailc"; ?>" /></font></td>
</tr>
<tr>
<td width="11"> </td>
<td width="118"><font color="#FFFFFF">
<b>Telefon</b>*</font></td>
<td><font color="#FFFFFF">
<input class="input" type="text" name="tlf" size="20" value="<?php echo "$tlfc"; ?>" /></font></td>
</tr>
</table>
</td>
<td width="2%"> </td>
</tr>
<tr>
<td colspan="2">
<p align="center">
<div align="center">
<font color="#FFFFFF">
<input type="hidden" name="done" value="yes" />
</font><font color="#FFFFFF">
<br />
<input class="submit" type="submit" name="submit" value=" Send " /> <input class="submit" type="reset" name="cancel" value='Slet'" /><br />
</form>
</font>
</div>
</td>
</tr>
</table>
<?php
}// if the email has been sent, will display thank you message above and links below
else {
echo "<a href=\"java script: history.go(-1)\">Tilbage</a><br />";
}
?>
<?php
} else {
?>
<!-- BRUGEREN HAR STEMT -->
<?
echo "du har stemt";
}
?>
</div></div></div>
</body>
</html>