?
Solved

PHP - Archiving Posts

Posted on 2003-03-09
3
Medium Priority
?
241 Views
Last Modified: 2009-12-16
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:

http://digitalparadox.modernfart.com/post.shtml

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

Thanks,
Harrison Chen
0
Comment
Question by:DigitalParadox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
VGR earned 300 total points
ID: 8101430
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<BR>";
  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<BR>";
//

  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<BR>";
//

  $result=mysql_query($query,$linkID) or die ("bad query get clean upload. ".mysql_error());
  if (mysql_num_rows($result)>0) {
    $compteur=0;
    $contenu="$locTo<BR>Effacement des fichiers pirimis dans upload :<BR><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<BR>";
//
      $totor=unlink("upload/$loc4");
//debug windows
//echo "risultat unlink = $totor<BR>";
//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><BR><BR>ce qui reprisente $compteur octets libiris.<BR>";
//test
//echo "$contenu<BR>";
//
  $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,

0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 11934203
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: VGR {http:#8101430}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

snoyes_jw
EE Cleanup Volunteer
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question