Solved

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

Posted on 2009-05-05
8
229 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
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now