Welcome! Log In Create A New Profile

Advanced

phpSumo

Posted by Riaz 
Announcements Last Post
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
avatar phpSumo
November 03, 2011 02:22PM
Hi Everyone,

I'm busy working on a PHP library, This is what I have so far if anyone has any idea's on what I can add to it I would appreciate it smiling smiley

Create a PHP file and name it phpSumo.class.php then paste this code inside

Language: PHP
/** * * Copyright (c) 2011 Riaz Sabjee * * Dual licensed under the MIT and GPL licenses: * http://www.gnu.org/licenses/gpl.html * */   class phpSumo {   function quotes($filename){ $filename = $filename; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $array = explode("\n",$contents); $quote = rand("0", (count($array) - 1)); return $array[$quote]; }   function hits(){ if(file_exists("hits.txt")){ $hits = file_get_contents("hits.txt"); $hits = file_put_contents("hits.txt", ($hits + 1)); } else { $hits = file_put_contents("hits.txt", "1"); }   $hits = file_get_contents("hits.txt"); return $hits; }   function protect($password=';';){ if(!isset($_SESSION["pSumoSecure"]) AND trim($_POST["psumo_pass"]) != $password){ echo ';This page is protected by a password:<br /><form action="" method="POST"><input type="password" name="psumo_pass" value="" /><input type="submit" name="submit" value="Login" /></form>';; exit(); } else { $_SESSION["pSumoSecure"] = trim($_POST["psumo_pass"]); } }   }   //INITIALIZE CLASS $phpSumo = new phpSumo();

Create a PHP file and name it phpSumo.php then paste this code inside.

Language: PHP
session_start(); //START A SESSION IF YOU USE protect   include("phpSumo.class.php");   //$phpSumo->protect("password"); //Page Protect NOTE: Will need [b]session_start[/b] to work   echo ';<p>';.$phpSumo->quotes("phrases.txt").';</p>';; //Quotes from a file echo ';<p><b>Website Hits: </b>';.$phpSumo->hits().';</p>';; //Count Website Hits

By calling: $phpSumo->hits() it creates a website hit counter for you.
By calling: $phpSumo->quotes( "phrases.txt" ) it will print out random text/quotes from file phrases.txt
NOTE: Each text or quote needs to be on a new line.

Example Quote File: Create a text file in notepad then save it as phrases.txt then drop it in the folder with the phpSumo.php file.
A person who never made a mistake never tried anything new. - Albert Einstein 
All our dreams can come true, if we have the courage to pursue them. - Walt Disney 
Design is not just what it looks like and feels like. Design is how it works. - Steve Jobs 
Defeat is not the worst of failures. Not to have tried is the true failure. - George Edward Woodberry
I need drama in my life to keep making music. - Eminem
Float like a butterfly, sting like a bee. - Muhammad Ali

By calling: $phpSumo->protect( "myPassword" ) it will password protect your page, add this line right on the top before your content.
You need to pass a specific password to the function, I have entered myPassword as an example.

Try it out give me some feedback, would appreciate it. thumbs up

student no: 77315138
Sorry, only registered users may post in this forum.

Click here to login