Jump to content

Please help! Writing to file.


acoole

Recommended Posts

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,

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!

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,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.