Solved

Simple time reservation site . . . . Can PHP use flat files?

Posted on 2009-05-05
8
238 Views
Last Modified: 2013-12-12
I want to create a trivial page where visitors can enter simple info (reserving a date and time slot for my service - dog walking ! )
Without an SQL interfaced DB, can I save user info and selections in another way, say on a flat file?
I dont need GB of space. Is there a simple site web host? with domain registration? I need a trivial PHP page that need only remember dates my users want my service.
Ideas?
I do have an always-on machine. Could I link that to a domain, with some php and simple db?
Trivial?

0
Comment
Question by:beavoid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 4

Assisted Solution

by:bleach77
bleach77 earned 50 total points
ID: 24311131
1. Yes, you can save it in a flat file. Database are mostly use for big data for easier search.
   Use fread and fwrite function.

2. You can link the domain to your computer. Given that you have a fix IP. Otherwise you have to change the IP of your site everytime your IP change. But I guess it will be much more easier to use a hosting site as it does not cost a lot nowadays. You can google for a cheap hosting :)
0
 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 450 total points
ID: 24312576
Try this sample code to get used to it.  I would however recommend a bit more advanced reading up on .csv plain text databases.  .csv are basicly plain text spread sheets that can be read by excel etc.  Reading and saving and updating CSV format is much easier in the long run than coming up with your own format for your text files.

PHP has functions for managing csv files... just try a Google search for some tutorials and you will be up and running really fast.

Also Bleach is right - there are good reasons to use a web host - not just very cheap but also they manage uptime, security and etc for you so you don't need to worry about it.  It's probably the best idea for serving a website as the service is more high tech and safer than serving from your own home or office in most circumstances.
$file = "full/path/to/your-text.txt";
 
$fp = fopen ($file,"r"); //open file for reading
$Data = fread($fp,filesize($file));  // read data save as $Data variable
fclose ($fp);
 
$fp = fopen ($file,"w+"); //open file for writing (and create the file if it not exists!)
fwrite($fp,$Data));  // save data to the file
fclose ($fp);

Open in new window

0
 

Author Comment

by:beavoid
ID: 24370831
Where will $file reside?
In the site's file directory, with the PHP files?
0
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 450 total points
ID: 24375123
Hi,

$file = "full/path/to/your-text.txt";

- The file can be wherever you want it to be *inside* your web directory... it could be along side your php files but it might be better to create another sub folder - perhaps "data/myfile.csv" or similar.

Cheers!
0
 

Author Comment

by:beavoid
ID: 24381310
So, i I get a google web-space, this file should be right there with index.php?
0
 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 450 total points
ID: 24387060
Yes you can put it there if you like so long as wherever you put it, it must match the path in your code :)
0
 

Author Comment

by:beavoid
ID: 24400883
Would you go for the tab spaced simple .txt DB for a trivial site like this?
I havent used .csv yet and the .txt should be fine.

I know all about CS 200 whitespace DB's

Does the $data up there return the entire file specified?
How do I delimit the  $data  tokens?
0
 
LVL 3

Accepted Solution

by:
NIPPLES earned 450 total points
ID: 24401449
Hi there,

CSV is plain text - just with delimiters.  A standard CSV will use something like...

"text","more text","even more text"
"text","more text","even more text"
"text","more text","even more text"
"text","more text","even more text"

You can also use a tab as the delimiter... to work with tabs in PHP they are similar to new lines ...

/r/n = new line
/t = tab

Finally yes, in the example above, $data variable contains the entire files text.  For much larger text files you may want to use a recursive file read with a buffer, maybe something like...


$CompleteData = "";
$ConnectionString = "path/to/your/file.txt";
 
$handle = @fopen($ConnectionString, "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 9096);
	$CompleteData .= $buffer;
    }
    fclose($handle);
}
print $CompleteData;

Open in new window

0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question