Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,426 members, 7,819,553 topics. Date: Monday, 06 May 2024 at 05:59 PM

Help A Newbie Php Programmer - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help A Newbie Php Programmer (1313 Views)

Help A Newbie / What Is The Average Salary Of A Php Programmer In Lagos (2) (3) (4)

(1) (Reply) (Go Down)

Help A Newbie Php Programmer by justjavac(m): 1:25pm On Oct 05, 2014
please..am trying to get the number of times a webpage in viewed, I.e accessed. Can anyone tell me how I can do that in php.
Re: Help A Newbie Php Programmer by Codedboy95(m): 2:15pm On Oct 05, 2014
justjavac:
please..am trying to get the number of times a webpage in viewed, I.e accessed. Can anyone tell me how I can do that in php.
here copy and paste this in a php file let's say count.php

<?php
$counter = "counter.txt";
$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
$current_date = $mday . $month . $year;
// Log visit;
$fp = fopen($counter, "a"wink;
$line = $REMOTE_ADDR . "|" . $mday . $month . $year . "\n";
$size = strlen($line);
fputs($fp, $line, $size);
fclose($fp);
$contents = file($counter);
$total_hits = sizeof($contents);
$total_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
array_push($total_hosts, $entry[0]);
}
$total_hosts_size = sizeof(array_unique($total_hosts));
$daily_hits = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hits, $entry[0]);
}
}
$daily_hits_size = sizeof($daily_hits);
$daily_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hosts, $entry[0]);
}
}
$daily_hosts_size = sizeof(array_unique($daily_hosts));
?>

then create a file counter.txt and include the file count.php where you want your counter to show

Re: Help A Newbie Php Programmer by justjavac(m): 5:47pm On Oct 05, 2014
please,does/will $daily_host_size contain the number of times the page has been accessed?
Re: Help A Newbie Php Programmer by Nobody: 11:13pm On Oct 05, 2014
o boy see codes o!
Re: Help A Newbie Php Programmer by Sethuncahier(m): 4:24am On Oct 06, 2014
Sorry for interfering. I'm a PHP learner,I want to ask that this variables quoted here e.g $daily,etc. Are the variables recognized generally? Or you can just creatively form a variable to use for your purpose. Thanks
Re: Help A Newbie Php Programmer by Nobody: 9:02am On Oct 06, 2014
Sethuncahier:
Sorry for interfering. I'm a PHP learner,I want to ask that this variables quoted here e.g $daily,etc. Are the variables recognized generally? Or you can just creatively form a variable to use for your purpose. Thanks
Its just a variable created creatively..Lol.. Well, he just named it to be a reminder of what the variable "daily" does.. Its a good naming system so as to remember what each variable does by merely looking at it..
Re: Help A Newbie Php Programmer by Sethuncahier(m): 11:05am On Oct 06, 2014
Djangocode:
Its just a variable created creatively..Lol.. Well, he just named it to be a reminder of what the variable "daily" does.. Its a good naming system so as to remember what each variable does by merely looking at it..
Ok! Thanks Boss. Now I understand. But I still need tutoring o! I've been comparing HTML coding and output with PHP. Its seem I can't correlate them that's why I really find it difficult to understand Variables, Arrays,etc.
Re: Help A Newbie Php Programmer by Nobody: 12:15pm On Oct 06, 2014
Variables and Arrays are quite easy to understand... Do u have a good book on php, You can email me for one... You dont need to declare a variable type in php before assigning a value to it.. Eg:
$age = 13;
$name = "tom";
echo $age;
echo $name;

This outputs 13 and tom respectively...

Just think of Variables as a container for an object and think of Arrays as a container for various objects or values..

If u are on bbm, U can add me for further questions u might have... Hope my explanation helped..
Re: Help A Newbie Php Programmer by Sethuncahier(m): 12:30pm On Oct 06, 2014
Djangocode:
Variables and Arrays are quite easy to understand... Do u have a good book on php, You can email me for one... You dont need to declare a variable type in php before assigning a value to it.. Eg:
$age = 13;
$name = "tom";
echo $age;
echo $name;

This outputs 13 and tom respectively...

Just think of Variables as a container for an object and think of Arrays as a container for various objects or values..

If u are on bbm, U can add me for further questions u might have... Hope my explanation helped..
Wow! Thanks I really appreciate how you've explained it. I don't have a book but have been reading online. I definitely gonna BBM you. Mine is 2188836B. You can give me yours too. Thanks very much.
Re: Help A Newbie Php Programmer by uchdollar111: 8:26pm On Oct 06, 2014
justjavac:
please,does/will $daily_host_size contain the number of times the page has been accessed?
Bro, how to use the code above is to copy and save it as count.php in your web root folder or wherever your other web pages are located, create a second file called counter.txt. Then in any page you want to show how many times the page has been viewed use a PHP function called include which just copies the content of the file you need into another file, that's when you will now use include('count.php'); to print the number of times the page has been viewed. I hope this helps, if you have any other problems, pls don't hesitate to ask.
Re: Help A Newbie Php Programmer by Djtm(m): 3:39am On Oct 07, 2014
dhtml18:
o boy see codes o!
was surprised too.
Re: Help A Newbie Php Programmer by ify01: 3:57am On Oct 07, 2014
Djangocode:
Variables and Arrays are quite easy to understand... Do u have a good book on php, You can email me for one... You dont need to declare a variable type in php before assigning a value to it.. Eg:
$age = 13;
$name = "tom";
echo $age;
echo $name;

This outputs 13 and tom respectively...

Just think of Variables as a container for an object and think of Arrays as a container for various objects or values..

If u are on bbm, U can add me for further questions u might have... Hope my explanation helped..
Are you on Fb?
Re: Help A Newbie Php Programmer by Nobody: 6:41am On Oct 07, 2014
ify01:

Are you on Fb?
Nope.. Only Whatsapp or BBM..
Re: Help A Newbie Php Programmer by mubitechnology: 10:52am On Oct 07, 2014
Djangocode I really like your explaination of variables and array, and for the op there is a similar example in beginner php 5.3 from wrox book in chapter 11 or 10 I think. Go get the book at it-book.com
Re: Help A Newbie Php Programmer by justjavac(m): 11:18am On Oct 07, 2014
Actually...I didn't expect all those codes just to fix my problem..so am suprise too. I didn't also see Whr d output is echoed out, making it more confusing for me..anyway tnks for ur code.@uchdollar, tnks for ur explanation...I will try it out. @mubitechnology tnk u Very much

(1) (Reply)

Help...my If Statement In Php Is Not Echoing / Freelance Web Developers And Software Engineers Urgently Needed / Im Very Sad

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 27
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.