Welcome! Log In Create A New Profile

Advanced

Task 3A, Task 3B, Task 3B-2

Posted by vad 
Announcements Last Post
Announcement myUnisa availability 21 to 24 March 2019 03/25/2019 12:25PM
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
vad
Task 3A, Task 3B, Task 3B-2
February 05, 2010 03:39AM
These tasks were successfully completed.

If you could pass variable contents from HTML to PHP then that would be the major problem you experience. No problem writing to the output file and no problem reading an input file hence displaying what was written to the output file. The directory navigation script presented no problem. I was able to execute the previous scripts that I had written.
Re: Task 3A, Task 3B, Task 3B-2
February 05, 2010 01:02PM
Seems the going is still good for now, I haven't really gotten a problem so far, I have beeen however a bit ambitious and looked into the future and did a thing or too, not soo rosy there, will need a bit more concentration
vad
Re: Task 3A, Task 3B, Task 3B-2
February 07, 2010 09:36PM
I am starting first with the exercises given in Masterskill. Once I complete these, I will work my way through the text book. There seems to be quite a few good examples which I think will give a good basis for project develpment in the real world. I used the text book( chapter 1 ) for reference while setting up the php.ini file and http.conf file. I really found it helpful. I also read the previous forums, which were really helpful.
avatar
Mac
Re: Task 3A, Task 3B, Task 3B-2
February 08, 2010 06:27AM
You need to use the textbook in conjunction with the manual, since thee manual is PHP4 and the textbook PHP5, XAMPP is PHP5, therefore you need to figureout how to adapt the PHP4 code from the manual.
Re: Task 3A, Task 3B, Task 3B-2
March 03, 2010 02:28PM
Hi

I have completed these

had to switch of notices again

Thanks

Kashmira
Anonymous User
Re: Task 3A, Task 3B, Task 3B-2
March 07, 2010 05:54PM
Hi
Was not that easy but
I have completed the task
Re: Task 3A, Task 3B, Task 3B-2
March 09, 2010 01:18PM
Completed tasks, interesting and very helpful (file, directory functions)
Tny
Re: Task 3A, Task 3B, Task 3B-2
March 09, 2010 11:19PM
Tasks 3A, Task 3B, Task 3B-2 completed successfully

Task 3B-2 proved quite tricky
Re: Task 3A, Task 3B, Task 3B-2
March 10, 2010 10:41AM
I am just having problems with this code, and check the error messages that I get,
Language: PHP
<?php $fp = fopen("./hit.txt" , "r"); if (!$fp) die ("Cannot open ./hit.txt"); $currenthits = fread($fp, 20); fclose($fp); $currenthits++;   echo "This Web site has been viewed by $currenthits people. " ; $fp = fopen("./hit.txt", "w"); fwrite ($fp, $currenthits); fclose($fp); ?>


This Web site has been viewed by 1 people.
Warning: fopen(./hit.txt) [function.fopen]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/hit_number.php on line 9

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/hit_number.php on line 10

Warning: fclose() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/hit_number.php on line 11


Someone help me please I am drowning
avatar
Mac
Re: Task 3A, Task 3B, Task 3B-2
March 10, 2010 10:49AM
the path must be wrong
./hit.txt

put hit.txt in the same directory that hit_number.php is in, and take the ./ out
Language: PHP
$fp = fopen("hit.txt" , "r");
Re: Task 3A, Task 3B, Task 3B-2
March 16, 2010 03:01PM
I have completed Tasks 3A, 3B and 3B-2

But I noticed an issue with the code - if more than one user were to request the same page at the same time (eg. task 3B ), the page would not execute as expected. What would happen is the two "requests" would open the Hits.txt file at the same time, read the same number, increment it, and write the same number back to the file. Thus multiple requests resulted in the hit count only being incremented once. I looked around and the solution is to lock the resource:

Language: PHP
$fp = fopen($filename,"r+b"); if(!$fp) return "0"; //could not open the hits file flock($fp,LOCK_EX); $num = fread($fp,4); //lock the resource so it can only be accessed once at a time $num++; fseek($fp,0,SEEK_SET); fwrite($fp,$num); fclose($fp); return $num;

In this excerpt of a function I wrote I:

* open the file
* lock the resource (with the flock function)
* read the number
* increment the number
* move the file cursor back to the begining of the file
* write the number
* close the file


I just thought that would be useful practically.
Re: Task 3A, Task 3B, Task 3B-2
March 16, 2010 03:58PM
I was also reading somewhere where it states that file locking is really necessary, apparently when multi-users access and write on a particular file, before adding their data/info , they first set a file at zero, that is deleting all other records before putting their own, so at the end of day there is a potential that after a thousand or so transactions, you might just have one record - the last one. So file locking apparently solves that problem, I have not figured out how though still I guess in time I'll figure out
Re: Task 3A, Task 3B, Task 3B-2
April 08, 2010 05:01PM
done with 3a,3b and 3b-2 get little time to make these posts
but well on tack.
MDC
Re: Task 3A, Task 3B, Task 3B-2
April 24, 2010 12:30PM
Done with these tasks as well. I've never worked with HTML so it's quite a steep learning curve, but well worth it.
Sorry, only registered users may post in this forum.

Click here to login