php - Call to function error -



php - Call to function error -

linux system

looking help function. i'm new learning them. mentioned create function maintain writing same code many times.

i have found many pages them , have helped i'm still having issues getting mine work.

it not giving log errors , nil beingness created. errors when starting know i'm missing something.

here have far.

thank in advance.

bob

<?php $dirpath = "path file location"; $buildpath = "path file location"; function createfiles() { ($i = 1; $i < 45; ++$i) { $filename = $buildpath . '/$area'. sprintf("%02s", $i) . '.php'; if (!file_exists($buildpath$filename)) { $myfile = fopen($buildpath$filename, "w") or die("unable open item$i file!"); fwrite($myfile, $txt1); fwrite($myfile, $addtitle); fwrite($myfile, $incltxt); fclose($myfile); chmod("$buildpath"."$area"."$i".".php", 0755); } // fopen, fwrite, fcloses... // filename delete page setup if (!file_exists("$dirpath"."delete.page.php")) { $myfile = fopen("$dirpath"."delete.page.php", "w") or die("unable open file!"); $txt = "<option value=\"\">select page delete......</option>\n <option value=\"generalinfo.tx\">general info page.</option>\n <option value=\"$filename\">$area pg. $i</option>\n"; fwrite($myfile, $txt); fclose($myfile); chmod("$dirpath"."delete.page.php", 0755); } else { $myfile = fopen("$dirpath"."delete.page.php", "a") or die("unable open file!"); $txt = "<option value=\"$filename\">$area pg. $i</option>\n"; fwrite($myfile, $txt); fclose($myfile); chmod("$dirpath"."delete.page.php", 0755); } break; } homecoming true; } if ($i == 1) { createfiles(); } // 1 time more 4 items written in each file need new file. // can happen maximum 11 times each session if ($i == 5) { createfiles(); } if ($i == 9) { createfiles(); } if ($i == 13) { createfiles(); } if ($i == 17) { createfiles(); } etc...... if($i == 49) { echo "<br />maximum of 12 pages hit. time delete few"; } ?>

$i if equals, , part working.

if part working, not showing code!

take example, fundamentally same doing:

function createfiles() { $i = 3; } if ($i == 3) { createfiles(); echo "is 3"; } else { echo "is not 3"; }

this echo "is not 3". var not set, 1 beingness set in function a) not within same global scope, , b) function has never been called.

how can var beingness manipulated within function determine in code outside function if same function should called if var within function set something? it's grab 22.

your function phone call createfiles() execute if $i == 1, , code posted not set var, null or unset (etc). means if statement calls function never work, , homecoming false, , function never called.

you have understand global scope, in vars within function remain within function, , outside function separate. have 2 vars, 1 within function, , 1 outside it, although still both named $i global scope not marry, never interact one-another.

you can pass var function allow vars , info outside function used within function, , homecoming 1 out of function using info outside function.

also, every time user uses code, vars reset, meaning bunch of ifs determine if have used x times not work desired. cannot client side.

you set session or cookie, client can bypass if want (cleaning browser data). if want limit them, need persistent info storage method client has no access - either file, or more solid method increment database value. if can utilize form 1 time again next day, cron run through table , clear required.

edit script working, seek introducing few stages create simple.

stage1: function working on it's own, adding files (or whatever purpose for). stage2: manipulate function beingness called how want - i.e. phone call function if user has used function < 10 (etc).

you break stage1 few sub stages, in stage1a, function accessing right directory; stage1b, function accessing files; stage1c, function writing files, etc.

try avoid writing script numerous areas of functionality in 1 go, , break manageable logical chunks. doing this, help see separation between different concerns.

php

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -