raulgonzalez
05-10-2005, 09:26 PM
Hello. I sell books online, through amazon.com and as my inventory got larger I decided to put up a webpage for those books so I bought my self a very usefull php book.
At that time I learned to write to MySql database and blabla.
After a few days I decided that I could make it more useful if I allowed others to sell their own books on my site so I did a little something and now when some one registeres to my site, they get their own folder which in turns is the same name as their username;
and copies of the original project.
Now here is the thing. For example if Joe registers he gets.
http://mysite.com/joe/index.php
up until now it has been working ok, but the way I am pulling it out is the one way I kind of don't think is the right way.
This is what I do.
At the time of registration one of the files gets created with the name of the registree inside the file. Here is an example.
//Escribiendo A El Archivo name.txt
$newfile = fopen("../$name/include_info/name.txt", "w");
fwrite($newfile, "<? \$name = \"$name\";?>");
fclose($newfile);
..............................................................
$name is the $name of the Username.
so I end up with a file like:
<? $name = "joe";?>
then in order to read joe's page I have that file included. example:
<?include ("name.txt")?>
and bla bla bla
more code
bla bla
and finlally
$query = "SELECT * FROM information where name='{$name}'";
so that gives me joe's information on
http://mysite/joe/index.php
..................................
I did this out of my butt and even though it works I was wondering if there is a better way to read the name of a folder instead of writing a file with the username's name on it.
example: a code inside any page within the /joe/ folder will return:
"joe".
or if anyone has a different idea. I was doing this for fun but after a while I thought it was interesting and that is why I now want to fix the code clean.
Thanks in advance.
At that time I learned to write to MySql database and blabla.
After a few days I decided that I could make it more useful if I allowed others to sell their own books on my site so I did a little something and now when some one registeres to my site, they get their own folder which in turns is the same name as their username;
and copies of the original project.
Now here is the thing. For example if Joe registers he gets.
http://mysite.com/joe/index.php
up until now it has been working ok, but the way I am pulling it out is the one way I kind of don't think is the right way.
This is what I do.
At the time of registration one of the files gets created with the name of the registree inside the file. Here is an example.
//Escribiendo A El Archivo name.txt
$newfile = fopen("../$name/include_info/name.txt", "w");
fwrite($newfile, "<? \$name = \"$name\";?>");
fclose($newfile);
..............................................................
$name is the $name of the Username.
so I end up with a file like:
<? $name = "joe";?>
then in order to read joe's page I have that file included. example:
<?include ("name.txt")?>
and bla bla bla
more code
bla bla
and finlally
$query = "SELECT * FROM information where name='{$name}'";
so that gives me joe's information on
http://mysite/joe/index.php
..................................
I did this out of my butt and even though it works I was wondering if there is a better way to read the name of a folder instead of writing a file with the username's name on it.
example: a code inside any page within the /joe/ folder will return:
"joe".
or if anyone has a different idea. I was doing this for fun but after a while I thought it was interesting and that is why I now want to fix the code clean.
Thanks in advance.
