acoole Posted March 8, 2008 Share Posted March 8, 2008 Hey there. I want to make a PHP script that will create a .ini file and write in it. I want it to create a $username.ini and then write in it some text. Is this possible, and if so an example please!, Thanks! Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 8, 2008 Share Posted March 8, 2008 http://www.php.net/fopen http://www.php.net/fread http://www.php.net/fwrite http://www.php.net/fclose Example: <?php // open file (or create if non-exists) - file.username.ini $file = fopen("file.".$_GET['usr'].".ini","a+"); // write contents fwrite($file,"file contents"); // close the file fclose($file); ?> hope this helps, Quote Link to comment Share on other sites More sharing options...
acoole Posted March 8, 2008 Author Share Posted March 8, 2008 Hey. Thanks, but what if I want to make it so it creates a .ini file with the username of the registered account on this script So say I was logged in as acoole using the register script when I runned the fopen script it would make a file called acoole.ini Register script: http://www.evolt.org/PHP-Login-System-with-Admin-Features Thanks! Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 8, 2008 Share Posted March 8, 2008 try reading the links i gave you and understand how fopen etc works. i will give a msll example that most likely wont be copy/pasted and voila effect. <?php $path = "./"; // this will prevent XSS // replace $_SESSION['username'] will the variable that holds your user name $file = fopen($path.$_SESSION['username'].".ini","a+"); // write contents fwrite($file,"username=$_SESSION['username'];password=$_SESSION['password'];optiona=yes"); // close the file fclose($file); ?> this would create "-username here-.ini" with the contents: "username=-username here-;password=-password here-;optiona=yes" obviously it will be your actual username/password and not "-username here-" literally. if $_SESSION['username'] = "acoole" it will create "acoole.ini" in the current directory with those contents. (NOTE: if storing passwords make sure its an encrypted/hashed string) (Also NOTE: The files created with with procedure will remain forever unless "unlink()" is used to delete the file) hope this helps, Quote Link to comment Share on other sites More sharing options...
acoole Posted March 8, 2008 Author Share Posted March 8, 2008 Helped ever so much. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.