WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Function for Random Digits
Categories : PHP, Beginner Guides Click here to Update Your Picture
Shashank Prabhakara
Date : Aug 31st 2008
Grade : 4 of 5 (graded 2 times)
Viewed : 2140
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Shashank Prabhakara
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

This is good only when you need to assign a random no. for and encryption or assign users on your site random no.s for something like registration for a page that lasts for a short period of time. you can get any no. of digits using this script. Simply call randomdigit( no. of digits required) and you dont get any leading zeros


<?php
function randomdigit($digits) {
static
$startseed = 0;
if (!
$startseed) {
   
$startseed = (double)microtime()*getrandmax();
   
srand($startseed);
}
$range = 8;
$start = 1;
$i = 1;
while (
$i<$digits) {
   
$range = $range . 9;
   
$start = $start . 0;
   
$i++;
}
return (
rand()%$range+$start);
}
?>



Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
Change the background color of a website daily dynamically using the php date function to get the current day of the week and depending on that day, set the background color for the web page.
Categories : PHP, Date Time, Beginner Guides, Web Design
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance.
Categories : HTML, PHP, HTML and PHP, Beginner Guides
PHP and javascript mouseover, mouseout, and mousedown events
Categories : PHP, Java Script, Form Processing, Beginner Guides
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
Simple Session example
Categories : PHP, Beginner Guides, Sessions
for each record, do this to the first record, and do that to any subsequent record
Categories : PHP, Databases, MySQL, Beginner Guides
Newbie Notes #5 - To double quote, or single quote, that is the question
Categories : PHP, Beginner Guides, Variables
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
SQLite PHP Database Wrapper
Categories : PHP, PHP Classes, Databases, SQLite, Beginner Guides
Newbie Notes #4 - Trapping dumb MySQL query errors
Categories : PHP, Databases, MySQL, Debugging, Beginner Guides
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
News management class
Categories : PHP, PHP Classes, Beginner Guides