Hi,
I was tring to prevent repetitive code writing by calling a function with a file name parameter to write the contents of that file to another file. To do this I called the function using url parameter. But, it lands me to some blank page. I must tell you that the code was working when I didn’t use the parameter run=function in the link, and using onclick() to call the function, but the function used to get called when I landed the page.
I used three sections of code as
[php]
if(isset($_GET[‘id’], $_GET[‘pg’]) && $_GET[‘id’]==‘link’){
//list of all the pages
include(“scripts/php/globel.inc.php”);
$pg=$_GET['pg'];
//$id=$_GET['link'];
if (isset($_GET['sess'])){
$sess=$_GET['sess'];
}
if (isset($_GET['run']) && $_GET['run']=='function'){
sesslogdata($current_file);
}
if($value=$page[$pg]) {
echo $value;
include("$value");
}
}
else {
include(“scripts/php/index.php”);
}
[/php]
[php]
$current_file = $_GET[‘sess’];
print ‘
[/php]
[php]
function sesslogdata($current_file) {
$temp_filename=$current_file;
$logout_time = date(‘d M Y g:i a’);
$var_logout=“logout-time:” . $logout_time . " | ";
$file_temp_sess = fopen (“scripts/php/” . $temp_filename, ‘a+’); // open a file write session data
flock ($file_temp_sess, LOCK_EX);
fwrite ($file_temp_sess, $var_logout); // write the session data to file
flock ($file_temp_sess, LOCK_UN);
fclose ($file_temp_sess);
$arr = “”;
$f = fopen(“scripts/php/” . $temp_filename, “r”);
// Read line by line until end of file
while (!feof($f)) {
// Make an array using comma as delimiter
$arr = fgets($f);
}
fclose($f);
$filehandle_sess = fopen (‘scripts/php/php_session.txt’, ‘a+’); // open a file write session data
flock ($filehandle_sess, LOCK_EX);
fwrite ($filehandle_sess, $arr); // write the session data to file
flock ($filehandle_sess, LOCK_UN);
fclose ($filehandle_sess);
$myFile = “scripts/php/” . $temp_filename;
unlink($myFile);
//return $arr;
}
[/php]