01. september 2005 - 12:09
#2
<ole>
Det er lidt uklart, hvad du mener. Hvis cookie'en skal sættes på baggrund af en brugerhandling, kan du gøre det på to måder:
1. sende resultatet af hans handling med til serveren og sætte kagen, som det første i dokumentet
2. sætte kagen med JavaScript på klienten
ob_start er en 'panikløsning', som bør undgåes :)
/mvh
</bole>
10. september 2005 - 09:02
#7
Du må da gerne se min løsning og komme med bedre forslag. Jeg ved godt at koden kan koges lidt ned!
<?php
session_start();
include("../data/setup.inc");
if ( $_COOKIE["LoginCookie"] == "hvadmonderskalståher") {
if ( $Sort == "datoId" ) {
}
else if ( $Sort == "senesteId" ) {
}
else if ( $Sort == "authorId" ) {
}
else if ( $Sort == "overskriftId" ) {
}
else {
$SortMetode = "DESC";
$Sort = "senesteId";
}
/////// Tæl antal forum her
global $AntalForumRound;
global $AktuelForumRange;
settype($AktuelForumRange, "int");
$conn = mysql_connect($DBsti, $DBuser, $DBpassword);
mysql_select_db($DBdatabase);
$result = mysql_query("select * from forums order by itemId asc");
while($row = mysql_fetch_array($result))
{
if ( $row["tekstId"] == "nej" AND $row["forumId"] > 0 AND $row["forumId"] <> $stoerste ) {
$AntalForum = $AntalForum + 1;
}
}
$LenAntal = strlen($AntalForum);
//$AntalForumRound = round($AntalForum / 2,0);
$AntalForumRound = substr($AntalForum,0,$LenAntal - 1) + 1 ;
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' -feltet skal udfyldes.\n'; }
} if (errors) alert('Følgende fejl opstod:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<link href="/alle/center1.css" rel="stylesheet" type="text/css">
<link href="../alle/style103.css" rel="stylesheet" type="text/css">
</head>
<body SCROLLBAR-ARROW-COLOR="66CCFF" background="/pics/main/backgrnd3.jpg" link="#006666" vlink="#006666" alink="#006666" leftmargin="5">
<h1>Forumoversigt</h1>
<br>
<table width="100" border="0">
<tr>
<td height="58" valign="bottom"><h3>Her kan du deltage i forskellige forum.</h3>
</td>
<td width="10" rowspan="2"> </td>
<td rowspan="2">
<form action="" method="post" name="form">
<table border="0">
<tr>
<td colspan="2"><h3>Sorter forum efter..</h3>
</td>
</tr>
<tr>
<td><input type="radio" name="radiobutton1" value="radiobutton" onClick="parent.frames['mainFrame'].location.href='forum.php?Sort=senesteId&SortMetode=DESC';"<?php if ($Sort == "senesteId") echo " checked" ?>>
</td>
<td nowrap width="104"><h3>Senest opdateret</h3>
</td>
</tr>
<tr>
<td><input type="radio" name="radiobutton2" value="radiobutton" onClick="parent.frames['mainFrame'].location.href='forum.php?Sort=datoId&SortMetode=DESC;'"<?php if ($Sort == "datoId") echo " checked" ?>>
</td>
<td nowrap><h3>Dato for oprettelse</h3>
</td>
</tr>
<tr>
<td><input type="radio" name="radiobutton3" value="radiobutton" onClick="parent.frames['mainFrame'].location.href='forum.php?Sort=authorId&SortMetode=ASC';"<?php if ($Sort == "authorId") echo " checked" ?>>
</td>
<td nowrap><h3>Author</h3>
</td>
</tr>
<tr>
<td><input type="radio" name="radiobutton4" value="radiobutton" onClick="parent.frames['mainFrame'].location.href='forum.php?Sort=overskriftId&SortMetode=ASC';"<?php if ($Sort == "overskriftId") echo " checked" ?>>
</td>
<td nowrap><h3>Overskrift</h3>
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height="58" valign="bottom" nowrap>
<h3 class="roed">Rød = indlæg siden sidste besøg</h3>
<h3 class="blaa">Blå = indlæg inden for de sidste 14 dage</h3>
</td>
</tr>
</table>
<h4>
<br>
<table width="100%" border="0">
<tr>
<td width="33%"><table width="166" height="27" cellpadding="0" cellspacing="0">
<tr>
<td nowrap height="25"><a href="#opretny"><img src="../pics/alle/ned2.gif" width="20" height="20" border="0"></a></td>
<td nowrap valign="bottom"><h2><a href="#opretny">Opret nyt forum</a></h2>
</td>
</tr>
</table></td>
<td width="33%">
<table border="0" align="center">
<tr>
<td width="42" height="21" nowrap>
<?php
if ( $AktuelForumRange == 0 OR $AktuelForumRange == "0") {
$AktuelForumRange = 1;
}
$ForskelOp = $AntalForumRound - $AktuelForumRange ;
$AntalEkstraOp = 3;
if ( $ForskelOp < 3 ) {
$AntalEkstraOp = $ForskelOp;
}
$ForskelNed = $AktuelForumRange - 3;
If ($ForskelNed < 1 ) {
$ForskelNed = 1;
}
settype($Lav, "string");
settype($Hoej, "string");
?>
<h3>Forum:</h3>
</td>
<?php
if ($ForskelNed > 1 ) {
?>
<td nowrap><a href="forum.php?AktuelForumRange=1&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>"><<</a></td>
<?php }
for ($z = $ForskelNed; $z <= $AktuelForumRange - 1 ; $z++) {
if ( $z == 1 ) { $Lav = 1; }
else { $Lav = $z - 1 . 1; }
$Hoej = $z . 0;
?>
<td nowrap><a href="forum.php?AktuelForumRange=<?php echo $z ?>&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>"><?php echo "$Lav-$Hoej"; ?></a></td>
<?php
}
$MidtLav = $AktuelForumRange -1 . 1;
$MidtHoej = $AktuelForumRange . 0;
?>
<td nowrap><?php echo "$MidtLav-$MidtHoej" ?></td>
<?php //$AntalForumRound
for ($z = $AktuelForumRange + 1; $z <= $AktuelForumRange + $AntalEkstraOp ; $z++) {
if ( $z == 1 ) {
$Lav = 1;
}
else
{ $Lav = $z - 1 . 1;
}
$Hoej = $z . 0;
?>
<td nowrap><a href="forum.php?AktuelForumRange=<?php echo $z ?>&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>"><?php echo "$Lav-$Hoej"; ?></a></td>
<?php
}
if ( $AntalForumRound - $AktuelForumRange > 3 ) {
?>
<td nowrap><a href="forum.php?AktuelForumRange=<?php echo $AntalForumRound; ?>&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>">>></a></td>
<?php }?>
</tr>
</table></td>
<td width="33%"> </td>
</tr>
</table>
<?php /////// Højeste forumnr listes her
$conn = mysql_connect($DBsti, $DBuser, $DBpassword);
mysql_select_db($DBdatabase);
$result = mysql_query("select * from forums order by itemId asc");
while($row = mysql_fetch_array($result))
{
if ( $row["tekstId"] == "nej" AND $row["forumId"] > $stoerste ) {
$stoerste = $row["forumId"] + 1 ; }}
//echo $stoerste ;
require("../data/mysql-funktioner.php");
// Reserver nr.
$sql = "UPDATE `forums` SET `forumId` = '$stoerste' WHERE `itemId` = '3' LIMIT 1 ";
//$sql = "UPDATE `users` SET `fuldenavnId` = '$fuldenavn' WHERE `logId` = '$hiddenfield' LIMIT 1 ";
//UPDATE `forums` SET `forumId` = $stoerste WHERE `itemId` = '3' LIMIT 1 ;
aabn_forbindelse_og_vaelgdb();
sql_spoerg($sql);
luk_forbindelse();
/////// Forumliste listes her
$Lige = false;
$conn = mysql_connect($DBsti, $DBuser, $DBpassword);
mysql_select_db($DBdatabase);
$result = mysql_query("select * from forums order by $Sort $SortMetode");
while($row = mysql_fetch_array($result))
{
if ( $row["tekstId"] == "nej" AND $row["forumId"] <> 0 AND $row["forumId"] <> $stoerste ) {
$Op = $Op + 1;
$Hoej = $AktuelForumRange . 1;
$Lav = $Hoej - 11;
if ( $Op > $Lav AND $Op < $Hoej) {
$datostreng = $row["datoId"] ;
$dag = substr($datostreng,8,2);
$maaned = substr($datostreng,5,2);
$aar = substr($datostreng,0,4);
if ($Lige == false) { $Lige = true; } else if ($Lige == true ) { $Lige = false; }
?>
<table width="100%" align="center" background="<?php if ($Lige == false ) { echo '../pics/alle/new-3.jpg'; } else { echo '../pics/alle/new-4.jpg' ;} ?>" style="border-top: 1px solid #000000; ">
<tr>
<td height="30" align="left" valign="bottom" >
<?php
$senesteklokken = substr($row["senesteId"],11,8);
$senestedag = substr($row["senesteId"],8,2);
$senestemaaned = substr($row["senesteId"],5,2);
$senesteaar = substr($row["senesteId"],0,4);
if ($_COOKIE["SenesteLoginCookie"] < $row["senesteId"]) { ?>
<h3 class="roed"><a href="/forum/valgtforum.php?forumID=<?php echo $row["forumId"] ;?>&emne=<?php echo $row["overskriftId"] ;?>"><?php echo $row["overskriftId"] ;?></a> Antal indlæg: <?php if ($row["nrId"]== "" OR $row["nrId"] == "NULL") {echo "0" ;} else {echo $row["nrId"] ; }?> Seneste indlæg:
<?php
if ($row["senesteId"]== "0000-00-00 00:00:00" ) {echo "" ;} else {echo $senestedag; ?>/<?php echo $senestemaaned; ?>-<?php echo $senesteaar; ?> kl. <?php echo $senesteklokken; }?></h3>
<?php }
else
if (strtotime($_COOKIE["SenesteLoginCookie"]) - strtotime($row["senesteId"]) < 1209600) { ?>
<h3 class="blaa"><a href="/forum/valgtforum.php?forumID=<?php echo $row["forumId"] ;?>&emne=<?php echo $row["overskriftId"] ;?>"><?php echo $row["overskriftId"] ;?></a> Antal indlæg: <?php if ($row["nrId"]== "" OR $row["nrId"] == "NULL") {echo "0" ;} else {echo $row["nrId"] ; }?> Seneste indlæg:
<?php if ($row["senesteId"]== "0000-00-00 00:00:00" ) {echo "" ;} else {echo $senestedag; ?>/<?php echo $senestemaaned; ?>-<?php echo $senesteaar; ?> kl. <?php echo $senesteklokken; }?></h3>
<?php }
else
{?>
<h3 class="sort"><a href="/forum/valgtforum.php?forumID=<?php echo $row["forumId"] ;?>&emne=<?php echo $row["overskriftId"] ;?>"><?php echo $row["overskriftId"] ;?></a> Antal indlæg: <?php if ($row["nrId"]== "" OR $row["nrId"] == "NULL") {echo "0" ;} else {echo $row["nrId"] ; }?> Seneste indlæg:
<?php if ($row["senesteId"]== "0000-00-00 00:00:00" ) {echo "" ;} else {echo $senestedag; ?>/<?php echo $senestemaaned; ?>-<?php echo $senesteaar; ?> kl. <?php echo $senesteklokken; }?></h3>
<?php
}
?>
</td>
</tr>
<tr>
<td width="80%" height="29" align="left" valign="top" >
<h3>Oprettet af: <?php echo $row["authorId"] ;?> Dato: <?php echo $dag ;?>/<?php echo $maaned ;?>-<?php echo $aar ; ?></h3>
</td>
</tr>
</table>
<?php
}}}
?>
<table border="0" align="center">
<tr>
<td width="42" height="21" nowrap>
<?php
if ( $AktuelForumRange == 0 OR $AktuelForumRange == "0") {
$AktuelForumRange = 1;
}
$ForskelOp = $AntalForumRound - $AktuelForumRange ;
$AntalEkstraOp = 3;
if ( $ForskelOp < 3 ) {
$AntalEkstraOp = $ForskelOp;
}
$ForskelNed = $AktuelForumRange - 3;
If ($ForskelNed < 1 ) {
$ForskelNed = 1;
}
settype($Lav, "string");
settype($Hoej, "string");
?>
<h3>Forum:</h3>
</td>
<?php
if ($ForskelNed > 1 ) {
?>
<td nowrap><a href="forum.php?AktuelForumRange=1&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>"><<</a></td>
<?php }
for ($z = $ForskelNed; $z <= $AktuelForumRange - 1 ; $z++) {
if ( $z == 1 ) { $Lav = 1; }
else { $Lav = $z - 1 . 1; }
$Hoej = $z . 0;
?>
<td nowrap><a href="forum.php?AktuelForumRange=<?php echo $z ?>&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>"><?php echo "$Lav-$Hoej"; ?></a></td>
<?php
}
$MidtLav = $AktuelForumRange -1 . 1;
$MidtHoej = $AktuelForumRange . 0;
?>
<td nowrap><?php echo "$MidtLav-$MidtHoej" ?></td>
<?php //$AntalForumRound
for ($z = $AktuelForumRange + 1; $z <= $AktuelForumRange + $AntalEkstraOp ; $z++) {
if ( $z == 1 ) {
$Lav = 1;
}
else
{ $Lav = $z - 1 . 1;
}
$Hoej = $z . 0;
?>
<td nowrap><a href="forum.php?AktuelForumRange=<?php echo $z ?>&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>"><?php echo "$Lav-$Hoej"; ?></a></td>
<?php
}
if ( $AntalForumRound - $AktuelForumRange > 3 ) {
?>
<td nowrap><a href="forum.php?AktuelForumRange=<?php echo $AntalForumRound; ?>&Sort=<?php echo $Sort; ?>&SortMetode=<?php echo $SortMetode; ?>">>></a></td>
<?php }?>
</tr>
</table>
<br>
<form name="form1" method="post" action="skrivnyforum.php">
<br>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h2><a name="opretny"></a>Opret nyt forum:</h2></td>
</tr>
<tr>
<td><h2>Oprettet af:</h2></td>
</tr>
<tr>
<td><input name="hidden" type="hidden" value="<?php echo $stoerste; ?>">
<input name="navn" type="text" size="30" maxlength="30">
</td>
</tr>
<tr>
<td><h2>Navnet på det nye forum:</h2></td>
</tr>
<tr>
<td><input name="overskriften" type="text" size="50" maxlength="50"></td>
</tr>
<tr>
<td height="43"><br>
<input name="indføj" type="submit" onClick="MM_validateForm('navn','','R','overskriften','','R');return document.MM_returnValue" value="Opret"></td>
</tr>
</table>
<br>
Nyt: Når du har klikket på Opret, bliver du nu dirigeret ind i dit nye forum, hvor du så kan skrive dit første nye indlæg i det nyoprettede forum
<br><br><br><br><br><br><br><br><br><br><br><br><br>
</form>
<a href="forum2.php">_</a></body>
<?php
} else {
?>
<html>
<head>
<title>login fejl</title>
</head>
<body background="/pics/main/backgrnd3.jpg">
Du har ikke adgang til denne side
</body>
</html>
<?php
}
?>