visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: PHP - Archiving Posts


By: DigitalParadox U.S.A.  Date: 11/10/2004 00:00:00  English  Points: 75 Status: Answered
Quality : Excellent
Hi,

I have created a script that allows members to make posts on a site. However, I would like to archive any posts other than the msot recent, lets say, 10, in a separate file. How could I achieve this? I was thinking i could put in a line of hidden code before each post that the sctipt would detect, and every time a post is made, it would remove and write into a new file the HTML code that follows the last of such a hidden line. Is this possible? Or is there another solution. I am trying to avoid MySQL, but if that is absolutely necessary, I will use it. The site I am talking about is here:

<A HREF="http://digitalparadox.modernfart.com/post.shtml">http://digitalparadox.modernfart.com/post.shtml</A>

If any existing script code is required, please e-mail me at harrisonchen@yahoo.com

Thanks,
Harrison Chen

By: VGR Date: 11/10/2004 07:34:00 English  Type : Answer
what I did is this :
1) I've an include on top of each page of my forum to check the existence of the session (and set default values like "visitor" if not). This is just after the session_start() pf course
2) in that file, whenever a user comes in "new" ("visitor") and is provided with the login page, I check chether I need to "backup" too-old messages
3) if yes, then I run a function to "clean-up the DB"
4) I prevent double-work by using a special table "status" built into each of my sites (message of the day, status of periodic actions,lastmod, forum status = closed, in maintenance, open, restricted, etc).

Simple and efficient

Let you have a look at this :

includedfile.php :
<?
session_start();
[some stuff here]
// now check forum's status and is there any cleaning up to do ?
$linkID=mysql_pconnect("$dbHost","$dbLogin","$dbPassword") or die ("bad connect".mysql_error());
mysql_select_db($dbName,$linkID) or die ("bad select DB ".mysql_error());
$query="select * from $dbTableStatus where id='1'";
$result=mysql_query($query,$linkID) or die ("bad query get forum status. ".mysql_error());
$res=mysql_fetch_array($result);
$sess_motd=$res["motd"];
$locCleanToDo=$res["CleanToDo"]; // this is the example I take for you
$locStatsToDo=$res["StatsToDo"];
$locMsgToDo=$res["MsgToDo"];

$sess_bloque=$res["bloque"]; // 0 -ok-,1 -plus poster avant mois suivant-,2-bloqui (nonpaiement)-

$locEtat=$res["etat"];
switch ($locEtat) {
case "0" :
$sess_shut="0";
$sess_restreint="0";
$sess_closed="0";
break;
case "1" :
$sess_shut="0";
$sess_restreint="1";
$sess_closed="0";
break;
case "2" :
$sess_shut="0";
$sess_restreint="1";
$sess_closed="1";
break;
case "3" :
$sess_shut="1";
$sess_restreint="1";
$sess_closed="1";
break;
default :
$sess_shut="1";
$sess_restreint="1";
$sess_closed="1";
LogAction($sess_pseudo,$REMOTE_ADDR,"Forum in abnormal status, closing...",2);
break;
} // switch
[... here some other irrelevant stuff]
$ov=$locCleanToDo;
$doIt=FALSE;
$poub=date("D");
// I'm only doing this for the first session renewed on each Monday
if ($ov==1) { // $locStatsToDo est synchronisi
if ($poub=='Mon') { $nv=0; $doIt=TRUE; }
else {$nv=$ov; } // R`F
} else if ($poub!='Mon') { $nv=1; $doIt=FALSE; }
else $nv=$ov;
if ($nv!=$ov) { // mise ` jour BdD
$query="update $dbTableStatus set CleanToDo=$nv, StatsToDo=$nv where id=1";
$result=mysql_query($query,$linkID) or die ("bad query set stats1 via query=$query . ".mysql_error());
}
// here I launch the real work of cleaning up a table !!
if ($doIt) { // travail effectif
$contenu='';
$contenu2='';
$Action=0; // on return below, indicates if processing has to take place or not
// this is the interesting lmine ; 6 is a number of days to come
$Action=CheckUpload(6,$contenu); // from dbvarious.inc
if ($Action==1) {
//VGR17112001 ADDed this automatic cleansing
LogAction('automate',$REMOTE_ADDR,'cleaning upload of obsolete entries...',2);
CleanUpload($contenu2);
} // if action
else LogAction('automate',$REMOTE_ADDR,'CHKUPL Monday, not yet done, but nothing to do',2);

} // do It

// now resume normal processing done on each request
if ($sess_shut=="1") {
LogAction($sess_pseudo,$REMOTE_ADDR,"rejection (forum is shut down) sessinc.",2);
echo "forum shut down for maintenance... come back later
";
exit; // sort du script
} else {
//VGR06052001 : ADDed liste noire (bannis)
// here I check banned IPs and Pseudos (black-list) etc
// now I offer the login form
// and if it passed OK, I read user's data from the DB, I set up his/her settings,
?>


NOW IN DBVARIOUS.INC I've this kind of function to clean up the "upload" area (DB's table and actual filesystem's directory for upload)
// please adapt to your needs
// the returned parameter contains the (HTML-formatted) list of files having been cleaned up, the total amount of bytes cleaned, etc - you can strip this
//
function CleanUpload(&$contenu) {
GLOBAL $dbHost, $dbName, $dbLogin, $dbPassword, $dbTableUpload,$sess_osWin;

$locTo=date('Y-m-d H:I:s'); //date("Y-n-j G:i:s"); // date du jour formatie en datetime-compatible
$locval=0;
//test
//echo "$locTo
";
//

if ($sess_osWin==1) $linkID=mysql_connect("$dbHost","$dbLogin","$dbPassword") or die ("bad connect".mysql_error());
else $linkID=mysql_pconnect("$dbHost","$dbLogin","$dbPassword") or die ("bad connect".mysql_error());
mysql_select_db($dbName,$linkID) or die ("bad select DB ".mysql_error());
//1 : dij` expiris
$query="select * from $dbTableUpload where expiration<='$locTo' order by dateheure asc;";
//test
//echo "query $query
";
//

$result=mysql_query($query,$linkID) or die ("bad query get clean upload. ".mysql_error());
if (mysql_num_rows($result)>0) {
$compteur=0;
$contenu="$locTo
Effacement des fichiers pirimis dans upload :
<UL>";
while ($res=mysql_fetch_array($result)) {
$loc1=$res["id"];
$loc2=$res["auteur"];
$loc3=$res["dateheure"];
$loc4=$res["nomfichier"];
$loc5=$res["destinataire"];
$loc6=$res["expiration"];
$loc7=addslashes($res["description"]);
$loc8=$res["taille"];
$compteur=$compteur+$loc8;
//test
//echo "$loc1 $loc4
";
//
$totor=unlink("upload/$loc4");
//debug windows
//echo "risultat unlink = $totor
";
//EoDebug
//VGR27042002 BUGFIX inversion du test sur $totor=unlink() .......
if ($totor!=0) $contenu.="<LI>OK EFFACEMENT $loc4 (ID=$loc1, taille=$loc8) d\'auteur $loc2 posti le $loc3 et dicrit par \"$loc7\"</LI>";
else $contenu.="<LI>IMPOSSIBLE D\'EFFACER (raison coderetour=$totor) $loc4 (ID=$loc1) d\'auteur $loc2 posti le $loc3 et dicrit par \"$loc7\"</LI>";

}
$contenu.="</UL>

ce qui reprisente $compteur octets libiris.
";
//test
//echo "$contenu
";
//
$query="delete from $dbTableUpload where expiration<='$locTo';";
$result=mysql_query($query,$linkID) or die ("bad query perform clean upload. ".mysql_error());
} // if travail ` faire

} // CleanUpload procedure

I don't give you function CheckUpload($parNJ,&$contenu), it's almost the same

Hope this helps,



Do register to be able to answer

EContact
browser fav
page generated in 336.344960 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page