|
|
Posted in Computers & Tech / How-To's and Tutorials / Programming / PHP
Author: khalilov Total-Replies: 4 A good way to figure out the traffic in your site and what pages need improvement is to keep a record of the visits of every page. In this tutorial, i will show you how to make a simple counter system. Simple counter:
Procedure:
CODE<?phpmysql_connect("localhost","username","password") or die(mysql_error); mysql_select_db("counter"); $result=mysql_query("SELECT* FROM counter WHERE `Page`='Main page'"); $row=mysql_fetch_array($result); $i=$row['Count']+1; mysql_query("UPDATE `counter`.`Counter` SET `Count` = '$i' WHERE CONVERT( `counter`.`Page` USING utf8 ) = 'Main page'"); echo "This page has ".$i." views!"; ?> CODEmysql_connect("localhost","username","password") or die(mysql_error);mysql_select_db("counter"); $result=mysql_query("SELECT* FROM counter WHERE `Page`='Main page'"); $row=mysql_fetch_array($result); This code connects to the database and fetches the array(in this case row) of the viewed page. Note: change the 'Main page' according to the names you entered in the table, example 'index.php', 'forums.php'..... CODE$i=$row['Count']+1;mysql_query("UPDATE `counter`.`Counter` SET `Count` = '$i' WHERE CONVERT( `counter`.`Page` USING utf8 ) = 'Main page'"); This code increments the number of views of the selected page which was stored in $row['Count'], next the code updates the database with the new count. Note: again change the 'Main page' according to the names you entered in the table, example 'index.php', 'forums.php'..... CODEecho "This page has ".$i." views!";This is optional, incase you want the page to view how many times it has been visited so far, not necassary. You can change the message into something more attractive. Note:You can insert this code anywhere. CODE<?phpmysql_connect("localhost","username","password") or die(mysql_error); mysql_select_db("counter"); $result=mysql_query("SELECT* FROM counter "); $row=mysql_fetch_array($result); echo "<table border=1 celspacing=1><tr><th>Page</th><th>Views</th></tr>"; echo "<tr><td>".$row['Page']."</td><td>".$row['Count']."</td></tr>"; while($row=mysql_fetch_array($result)) {echo "<tr><td>".$row['Page']."</td><td>".$row['Count']."</td></tr>"; } echo "</table>"; ?> CODEmysql_connect("localhost","username","password") or die(mysql_error);mysql_select_db("counter"); $result=mysql_query("SELECT* FROM counter "); $row=mysql_fetch_array($result); This gets the FIRST row in the table we made. CODEecho "<table border=1 celspacing=1><tr><th>Page</th><th>Views</th></tr>";echo "<tr><td>".$row['Page']."</td><td>".$row['Count']."</td></tr>"; This makes a table and views the data of the first page in it. CODEwhile($row=mysql_fetch_array($result)){echo "<tr><td>".$row['Page']."</td><td>".$row['Count']."</td></tr>"; } echo "</table>"; Using the while loop here, we can get every row in the table until it ends, when the table ends the mysql_fetch_array function returns false. So, with each value a new row is shown. When the table ends and false is return the loop ends and the table is closed. If you are wondering why i didn't do this in the begining instead of addressing the first row alone, well that is because in some cases the first row will be skipped, according to my experience anyways. There you go a simple counter for your website, feel free to use,modify but not sell it
Mon Oct 20, 2008
Reply New Discussion
Posted in Computers & Tech / Programming / Scripting / PHP
Author: thenumberone Total-Replies: 18 Is there anyone got a online timed test script?Or anyone knows how to create this script? I wait your answers and all php programmers.
Wed May 10, 2006
Reply New Discussion
Posted in Computers & Tech / Databases
Author: NilsC Total-Replies: 7 Did you take a look at the counters on this webpage. There should be one there that you can use to count pagehits, so if you treat each picture as a page then the count will be accurate. Hotscripts.com I have not tried any of the scripts live uet but I have a couple that I'm testing. Nils
Mon Jan 31, 2005
Reply New Discussion
Posted in Computers & Tech / How-To's and Tutorials / Programming / PHP
Author: websaint Total-Replies: 38 Hi!! I'm going to show you how to make your own counter useing php!! So here comes the script: CODE<?php//Simple class for counting visits //Written by WebSaint class Teller { function count() { $countfile = file("alle.txt"); $count = $countfile[0]; $count= $count + 1; $fp = fopen("alle.txt","w"); $fw = fwrite($fp,$count); fclose($fp); echo $count; } } $obj =& new Teller; $obj->count(); ?> Then add this to display the number of visitors: CODE<p>Number of guests visiting my site: <? include('alle.txt'); ?>.</p>That's it. I hope you'll find the script useful!
Tue Sep 28, 2004
Reply New Discussion
Posted in Computers & Tech / Designing / Web Design and HTML
Author: szupie Total-Replies: 5 I Googled around and found a solution. It requires PHP, which you'll be able to use if you're hosted here. Anyway, here's the code: QUOTECODE/* Start the session */session_start(); /* Define how long the maximum amount of time the session can be inactive. */ define("MAX_IDLE_TIME", 3); function getOnlineUsers(){ if ( $directory_handle = opendir( session_save_path() ) ) { $count = 0; while ( false !== ( $file = readdir( $directory_handle ) ) ) { if($file != '.' && $file != '..'){ // Comment the 'if(...){' and '}' lines if you get a significant amount of traffic if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60) { $count++; } } closedir($directory_handle); return $count; } else { return false; } } echo 'Number of online users: ' . getOnlineUsers() . '<br />'; The MAX_IDLE_TIME is counted in minutes. Basically, this code starts a session for every visitor of your site, and then, when the page is being processed, it counts the total number of sessions and outputs the number.
Fri Mar 3, 2006
Reply New Discussion
Posted in Computers & Tech / Programming / Scripting / PHP
Author: TavoxPeru Total-Replies: 8 Hi, there is sometimes that you need to password protect a directory in your site but you dont have access to a database or you dont need it because only a few users will access this directory, well the following script i develop will help in this situation. With only 2 files you can implement a basic security, the first file is a simple txt file where you store your users information and the second file is the php script. You can name the files whatever you want and can be used in any site with php support. The users.txt file: In this file simply put one line at the time your users information like this: username1|userpassword1 username2|userpassword2 . . usernamen|userpasswordn The chksec.php file: This file is the one that implements the basic security, here is the code: CODE<?phpif(!isset($_SERVER['PHP_AUTH_USER'])){ Header("WWW-Authenticate: Basic realm=\"Restricted Access\""); Header("HTTP/1.1 401 Unauthorized"); echo "Authorization Required."; exit(); } $theFile=file("users.txt"); $nUsers=sizeof($theFile); $i=0; $validated=FALSE; while ($i<$nUsers && !$validated){ $aFields=explode("|",$theFile[$i]); if (($_SERVER['PHP_AUTH_USER']==$aFields[0])&&($_SERVER['PHP_AUTH_PW']==chop($aFields[1]))) $validated=TRUE; $i++; } if(!$validated){ Header("WWW-Authenticate: Basic realm=\"Restricted Access\""); Header("HTTP/1.1 401 Unauthorized"); echo "Authorization Required."; exit(); } ?> Thats it, to work you just need to include this file in another php file. For example: CODE<?phpinclude("chksec.php"); echo "Welcome back " . $_SERVER['PHP_AUTH_USER']; ?>
Fri Jun 9, 2006
Reply New Discussion
Posted in Others / Introductions & Welcome (N..
Author: SunBlind Total-Replies: 10 Hi, my name's Rae, nice to meet you all! I'm a 19 year old single mother living in Maryland. I love designing websites (even though they're not that great), I dabble a little in PHP scripting, and I love to help other people. (I aslo like anime
Tue Jun 28, 2005
Reply New Discussion
Posted in Computers & Tech / Internet and Websites
Author: Aequitas619 Total-Replies: 9 Ho do I decide if I should use a form to space out my page or a frame? Ive looked up both but Im not quite sure which way to go about it! My website is HTML based but the newer pages also contain php. Basically, I want to put a block of links on the left side but keep them seperate from the rest of the page! I think im meant to use forms, but do i start by defining the form? How do I specify which form Im working with? Thanks
Fri Dec 8, 2006
Reply New Discussion
Posted in Computers & Tech / Programming / Scripting / PHP
Author: ChronicLoser Total-Replies: 13 Alright, here is a UNIQUE counter I made that requires php. A unique counter only counts how many DIFFERENT users go to your site. In other words, if you have fifty users who clicked on you site two hundred times, it will only show 50. Alright, first things first. Assuming you have windows, right click on your desktop, and make a new text document. Rename the document to "unique.dat". Alright, make another new text document. Now open up your new text document and paste this into it: CODE<?php$filename = "unique.dat"; $file = file($filename); $file = array_unique($file); $hits = count($file); $remote = $_SERVER["REMOTE_ADDR"]; $wholefile = file_get_contents($filename); if (preg_match("/$remote/i",$wholefile)) { echo $hits; } else { $fd = fopen ($filename , "a+"); $fout = fwrite ($fd , "$remote\n"); fclose($fd); echo $hits; } ?> Done? Alright, now go back to the desktop, and rename this text document "unique.php". Now upload the two files into your hosting account (whether, it's through cpanel or an ftp application). Set your "unique.dat" to CHMOD 777. You're done. Now, wherever you want the number to be displayed on your site, place this in the html of your php file: CODE<?php include("unique.php"); ?>It will only display the number so if you want you can also do something like this to display "unique hits = #" CODEunique hits = <?php include("unique.php"); ?>And that's that. I tried to go through step by step, but if you need additional help feel free to ask ^_^
Sat Feb 19, 2005
Reply New Discussion
Posted in Computers & Tech / Designing / Graphics Design
Author: marijnnn Total-Replies: 15 why wouldn't it be possible to create a dynamic website with it? just have php/asp(.net)/jsp fill in the text inside the table, and you have a dynmaic website. make some parts into links and it'll work just fine
Thu Nov 11, 2004
Reply New Discussion
Posted in Computers & Tech / Internet and Websites
Author: Yaghoob Total-Replies: 4 Thanks for your useful information. Sorry for interruption I think you can help me, Please see this topic: Rss/atom Feed For Php Excuse me
Thu Mar 8, 2007
Reply New Discussion
Posted in Computers & Tech / How-To's and Tutorials / Websites and Web Designing
Author: onthescreen Total-Replies: 1
The How To's and What Not's of Web Design
ByOnthescreen Whats Included:
1. Setting up Your Server
First Steps:1. Download Xampp for your system: Linux: http://www.apachefriends.org/en/xampp-linux.html Windows: http://www.apachefriends.org/en/xampp-windows.html Mac OS X: http://www.apachefriends.org/en/xampp-macosx.html Solaris: http://www.apachefriends.org/en/xampp-solaris.html 2. Follow Directions on the appropriate page. 3. Test it! http://localhost/ 4. You're Done!
2. Where to Start
I recommend you find a coding program such as Adobe/Macromedia Dreamweaver. When you code your programs don't include directories(folders) under your primary folder. Ex: CODEGood Code:<IMG SRC="/home.jpg"> <IMG SRC="/images/home.jpg"> Bad Code: <IMG SRC="File://C:\Server\image.jpg"> <IMG SRC="File://C:\Server\images\image.jpg"> First we need a layout. Depending on your type of website you may need different things. Save your files in your server folder(Wherever you installed it) 99% of the time you want to put it in the "/www/(your project name here)/" folder. Family Type Layout: A simple type of page. Not much is really needed here. Languages Needed: HTML 1. Set up a simple TEXT layout. Pick what type of pages you want (Family Tree, Pictures, Events, etc.) 2. Start each page as a blank .html file. 3. Work on the home page, it should be saved as "index.html" if you don't it wont work! Home Page Should Include:
Continue To Part 3 If you chose this layout, if not continue down. Forum Type Layout: This is somewhat more difficult than some people may think... This can be put into any website. Languages Needed: Some PHP, Some MySQL*, HTML * 90% of forums require a MySQL database, or a similar database. Its good to know how to use one. 1. Set up a homepage. 2. Start each page as a blank .html file. This may be changed later. 3. Work on the home page, it should be saved as "index.html" if you don't it wont work! Home Page Should Include:
A list of Forums: MercuryBoard Ultimate PHP Board (UPB) phpBB Forum (I use phpBB2, it works great and is semi-easy to customize.) Zorum Community Forum Software tForum Bulletin Board System XMB Forum Phorum Message Board NOTE: I have not used/guarantee the availability of ANY of these forums. (Unless otherwise noted.) 4. Download a forum source code. 5. You are finished with this step, Do step 4. Continue To Part 3 If you chose this layout, if not continue down. More Detailed Layouts Coming Soon.
3. Finding a Host/Uploading
Currently you are on a host site if you don't like this package try http://www.110mb.com If you plan to use PHP or MySQL make sure your host supports it. Freewebs does NOT support either! If you use MySQL(or other) make sure you create your database first! Good List of Hosts: http://www.freewebsiteproviders.com/free-domain-hosting.php Uploading If you have a PHP uploader you may use that, if not use your ftp connection you got with your site. 1. Upload all pages, folders, and files. If your website restricts .htaccess files they are NOT required. Put your Forums(if any) in separate folders. 2. Test it. Put your URL into your browser and check all links and pictures. 3. For those with forums continue. Everyone else is finished!
4. Forums
1. Somewhere in your forum folder there will be some kind of install.php file, run it on your host. NOT YOUR COMPUTER! 2. Follow the directions, you should have set up your database by now. 3. When your finished make sure you get rid of any install files, they could be dangerous to leave intact! Note: Some forums require SMTP or the PHP mail function. Some Hosts dont offer those for free, you may need to make it to where you cant verify your forum accounts.
5. Version Info/Contact Info
Current Versions:
Coming Soon:
~This is NOT the finished product! More may be coming soon!~ Copyright © 2007 DXK Productions
Mon Jun 11, 2007
Reply New Discussion
Posted in Astahost / Hosted Members Support
Author: spistols678 Total-Replies: 13 What is the best content manager out there? I think it's PHP-Nuke.
Thu Apr 21, 2005
New Discussion
Posted in Astahost / Your Voice! Your Review..
Author: AUSTiiN262 Total-Replies: 18 i have made two sites.....well attempted too....i have had so much trouble. i had trouble wit the counters, mail and even putting php, xhtml and html into the web-making thing they use. i used to get so frustrated!!! haha. i do not recommend it anyone.
Fri Apr 6, 2007
Reply New Discussion
Posted in Computers & Tech / Advertising / CPC, Online Adverising Network..
Author: rvalkass Total-Replies: 27 Project Wonderful might fit what you're looking for. They are somewhat unique in that people pay for the time their ads show on your site rather than the number of impressions or clicks, so you are guaranteed the income. I think you're also able to screen adverts before they are shown on your site, so you can make sure they're suitable to be shown. Advertisers bid for the various ad places on your site, setting how much they're willing to pay per hour, and also a daily limit. The person who will pay you the most, that hasn't reached their limit, will have their ad shown in that slot. Project Wonderful have a helpful guide here to show you how the auctions work, so you can see if it's what you're looking for: http://www.projectwonderful.com/advertisewithus.php
Tue Oct 6, 2009
Reply New Discussion
|