Page 1 of 1

fwrite question

Posted: Thu Jun 24, 2004 6:17 pm
by fresh
hello,

im trying to write to an htm doc, which will be generated from PHP like so;

Code: Select all

// check if pass is correct
$sp = $_GETї'name'];
$perm = $_GETї'pass'];
if(!$sp) {
echo "We're sorry... you must enter a name to login.";
} else {

if($perm == "0"){   //if it's ALL good move to main

//opens file for writing
$fp = fopen("".$sp.".htm","a+");

//write string to htm file
fwrite($fp, $sp);
fclose($fp);
now in the above example, the users name is saved with an htm ext, given the user a mini account, without the use of sql, etc... which is what I am trying to avoid... what I would like is to dynamically print a div box and then eventually as the user progresses, the users page will update with new info...

if I can get a confirmation on this one question I feel like I could wing the rest...

so, is it correct to do this:

Code: Select all

fwrite($fp, $sp);
echo "<div style="blah" etc...>";
echo "etc...";
fclose($fp);
would that write the div to the user.htm file? I know I could throw the variables in with the html code and use those to help in updating dynamically, so all i want to know is how to write html code to an htm file dynamically via PHP, while passing variables...

thanks in advance

Posted: Thu Jun 24, 2004 6:21 pm
by feyd
no..

Code: Select all

$str = '<div style="blah" etc....>';
fwrite($fp,$str);
would however.

great

Posted: Thu Jun 24, 2004 6:53 pm
by fresh
so would I just go like this:

Code: Select all

$str1 = "<div style='blah'>";
$str2 = "blah";
$str3 = "</div>";
fwrite($fp, $str1, $str2, $str3);

thanks in advance

Posted: Thu Jun 24, 2004 6:58 pm
by feyd
fwrite($fp,$str1.$str2.$str3);
or
fwrite($fp,$str1);
fwrite($fp,$str2);
fwrite($fp,$str3);

nice

Posted: Thu Jun 24, 2004 7:15 pm
by fresh
thanks alot!!! :D

new question same subject

Posted: Thu Jun 24, 2004 7:46 pm
by fresh
i noticed that this could be bad because if someone inputs a name already existant, then it would probably overwrite that users file... how could I code an ' if this file exists say this' script... remember I am using htm files to store the data not sql...

thanks in advance

Posted: Thu Jun 24, 2004 7:48 pm
by markl999

yes

Posted: Thu Jun 24, 2004 8:21 pm
by fresh
that did it... thank you guys alot... php is an awesome language isn't it? :D