Page 1 of 1
trying to create a script.. problems
Posted: Sun May 19, 2002 6:02 pm
by cabra
I'm making a script that adds about 6 lines of code to the .htaccess file. What the code in the .htaccess does is basically make sub domains with a cname and folder re-routing. Anyway, I have a login section where the admin logs in and is able to create a new sub by filling in some information. I've made that part of the script, and writes to the .htaccess fine. the problem i'm having is I don't know how to make a delete feature or edit feature, and i'm semi-new to php. I don't have MySQL access either. Can anyone help me?
Posted: Sun May 19, 2002 6:17 pm
by volka
Posted: Sun May 19, 2002 9:44 pm
by lc
Basicly you're creating a textfile with a line for each sub no?
What I do in similar cases when using flat (text) files and I want to be able to delete and edit certain lines is not use a normal write command.
But what I do is use
Code: Select all
$file = file("thefile");
// to get the content of the file
$fileї$nr] = "";
// incase of delete and $nr being the line number of the line you want to delete.. or
$fileї$nr] = "$editedcontent";
// in case of edit of a certain line.
// then
$a1 = fopen("thefile", w+);
flock($a1,2);
foreach($file as $key){
fwrite ($a1, $key);
}
fclose($a1);
// to write all in the file
Basicly what you do is get all the content from the file as $file first... then alter those lines in the array $file so that they become what you want them to.
Once that's done you open the file with w+ which basicly removes everything from the file.
Then use a foreach loop to rewrite all the data in the $file array into the file... and this contains the edited data.
Basicly I've found that this works rather perfectly
hope that helps
lc
Text Databases
Posted: Mon May 20, 2002 5:41 am
by ShrineMaster
If you don't have access to a database like MySQL, but you can have php writeable files/directories you can use text files as databases.
Check out this function, it'll help you get a start on a simple database.
fgetcsv()
http://www.php.net/manual/en/function.fgetcsv.php
I've used it on several of my own sites, works rather well for simple stuff.