It is currently Thu Mar 28, 2024 10:06 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: shortcut
PostPosted: Tue Apr 25, 2006 1:34 pm 
Experienced
Experienced

Joined: Fri May 13, 2005 10:24 am
Posts: 54
I'm re-writing my current mysql log system for this site, and I was wondering how to get the page that called a function, what I want is not the URL of page, but the filename of the included file that calls my function.

for example, my index.php page includes the register page, the submision to the database means that I store the data in the mysql log, so far all I can get is index.php or the URL, unless I start trailing around a variable called $curr_page or something.

Code:
function RunMySQL($funcs_query){
  $funcs_mysql_log = fopen("/home/www/beta/logs/mysql.txt", 'a');
  if(!fwrite($funcs_mysql_log,
                                           "\nuser - ".$_SESSION['id']."\n"
                                          .$funcs_query)){
    $errs[] = "error reporting mysql log.";
  };
  fclose($funcs_mysql_log);
  $funcs_mysql_rslt = @mysql_query($funcs_query);
  if(!$funcs_mysql_rslt){
    $errs[] = mysql_error();
  };
  return $funcs_mysql_rslt;
};


Last edited by scragar on Wed Apr 26, 2006 11:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 3:21 pm 
Posts like crazy!
Posts like crazy!

Joined: Mon Sep 26, 2005 5:03 pm
Posts: 204
Location: The Netherlands
$_SERVER['PHP_SELF'] won't work.. as I understand that he wants it for included pages aswell. __FILE__ Does work though.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 11:21 am 
Experienced
Experienced

Joined: Fri May 13, 2005 10:24 am
Posts: 54
Thanks, __FILE__ is exactly what I was looking for.

I have to parse it into the function, but it works.

Just in case anyone else wants to use it. It's great it you empty the log at the same time as you backup the database, this way anytime you(or someone else) messes something up you can just recreate the DB from the backup and your mysql-log.
Code:
<?
function RunMySQL($funcs_query, $funcs_file){
  $funcs_mysql_log = fopen("/home/www/beta/logs/mysql.txt", 'a');
  if(!fwrite($funcs_mysql_log,
                          "id - ".$_SESSION['id']."\n"
                         ."page - ".$funcs_file."\n"
                         .str_replace("\n", " ", $funcs_query)."\n")){
    $errs[] = "error reporting mysql log.";
  };
  fclose($funcs_mysql_log);
  $funcs_mysql_rslt = mysql_query($funcs_query);
  if(!$funcs_mysql_rslt)
    $errs[] = mysql_error();
  return $funcs_mysql_rslt;
};

RunMySQL("UPDATE tblUsers SET Uname = 'bob' WHERE id=10",
                             __FILE__);
?>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
100WebSpace © 2011