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,

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.