Saturday 10 April 2010

How to generate random passwords for PHP users.

Hey guys.

I have a script that I'd like to share and it is about generating random password. You can very well use this script for your new user registration. And then mail it to them.

This is useful when people create accounts and have easy to remember passwords but passwords shouldn't be easy to guess. Therefore, this script is going to output something that will be hard for user to guess.

Here it is:

function GeneratePassword($min = 5, $max = 8) {
$ValidChars = "abcdefghijklmnopqrstuvwxyz123456789";
$max_char = strlen($ValidChars) - 1;
$length = mt_rand($min, $max);
$password = "";
for ($i = 0; $i < $length; $i++) {
$password .= $ValidChars[mt_rand(0, $max_char)];
}
return $password;
}
echo "New Password = " . GeneratePassword()
. "\n";
echo "New Password = " . GeneratePassword(4, 10) . "\n";




Now all you have to do is call this function and you are there!

Enjoy!

How to Set an upload limit in PHP for a file.

Alright guys here it is. Very straight-forward.

I will this with you. It may be easy to locate but most of the people aren't aware of it. So here it goes.

All you need to do is locate and open you php.ini file and just look for this word:

upload_max_filesize

It will look something like this:




And in this figure the upload limit is set to 2 Megabyte. You can set any limit you want. You can increase it or decrease the limit.

Its your choice depending upon the server capability and network traffic you have over the server.

Enjoy and leave your comments down below.

Thanks!

How to Enable/Disable Image upload in PHP

Hey Guys as promised I have yet another tip to share with you.

In this post I am going to talk about how we can disable the file upload in PHP. It is fairly we simple.

All you have to do is just open up you php.ini file and locate the word:

file_uploads

As shown in the image below:



Now you can turn it On or Off.

If you turn it off the server will not accept any file uploads. Its that simple!

Enjoy!

Sunday 4 April 2010

New Cool stuff in Javascript!

Hey guys, today I learned some new stuff in Javascript. I am gonna share 'em with you later on.

Just keep tuned in as they are pretty cool stuff.

Cheers!

How to check if a file exists in your Web Server!

One thing I came across which was quite interesting was to check if a file exists before we do any operation on the file itself.

We do that by using a php function and we do that by:

if (file_exists('file.txt')) {
print 'OK, file.txt exists.';
}

Alright this is pretty much self-explanatory, here what we are doing is checking if the file exists or not. And if does, we simply print the message. You can simply use this function in your programs before working with the file otherwise this might throw an error if the file doesn't exists.

Very simple!

Making a String Uppercase, Lowercase, or Capitalized!!

Ok in this post I am going to show you how to Uppercase, Lowercase, or Capitalize a string or a word, I mean, making a work UPPERCASE or lowercase or Capital Word. Hmm now I guess I got things much clearer for you.

Now we'll first start with uppercase, the way we do that is:

$string = "heY hOw arE yoU doinG?";
echo strtoupper($string);
// Displays "HEY HOW ARE YOU DOING?"

What we did here is we used a PHP function called string to upper or strtoupper()

Likewise, we have the string to lower i.e strtolower()
echo strtolower($string);
// Displays "hey how are you doing?"

And yes, of course, we have the last one... called Uppercase. What this will do is uppercase everything:

$string="hoW ARE yOU doInG?";
echo ucwords(strtolower($string));
// Displays "Hey How Are You Doing?"

Important: Here, we have used a function ucwords() but before we did that we used the strtolower() function to lower case all the characters in the string... then.... we Capitalized the words in the string. Make sense?

I hope it did.

Enjoy and leave comments below!

How to check if a variable is null in PHP!

As we were talking about various functions in PHP, one of the functions to check if the value is null is: is_null($MyVal) and here if the values is null it will return true and false if the value is not null.

You can always go for something like: !is_null($MyVal) that way, if the value is not null then do something.

Very simple and straight forward!

Ok again, leave your comment down below.

Cheers!

How to Check if the number is numeric in PHP.

When you are working with functions in PHP and sending numeric data you always might want to check if the number passed is an integer.

We do that by using an built-in function and that is is_numeric($MyNum) here $MyNum is a variable that is passed to this function and we can always have if-else condition i.e it will return true if numeric or false if not numeric or vice-versa.

If you take a look at the php documentation, there are plenty of functions that you can look into.

I just thought of sharing this one with you. coz this one is very simple and it can save a lot of time trying to figure out what went wrong if the user has sent data in an incorrect format.

Cheers!

And don't forget to leave comments down below

What is cURL?

First of all, I am gonna talk about what cURL is then I will tell you what it does.
cURL is an extension in PHP which allows your PHP server to access other websites, sending and receiving information via a URL-like protocol. (You'll most commonly use HTTP, which lets you talk to other web pages, and FTP, which allows you to upload and download files.) In practical terms, this means you can have your server imitate a web browser, go to other sites, and download their web pages into a variable of your choosing.

cURL is a vital tool for any serious online shopping cart, because it allows you to approve credit card charges and get live shipping quotes for customers. You use cURL to connect and send transaction data to another company's server. The server replies, telling you information such as whether the charge was approved or denied and why.

Please leave your comments down below about how you found this post. I am pretty sure it will help you in some way.

Saturday 3 April 2010

What is PHPinfo() ?

When you are working with PHP, this is the all important question!

Basically, this is a function, a built-in function I might add is having all the info about your web server.

It lets you know where you configuration file is stored (i.e. the php.ini file) and the version of PHP you are using.

Not only that, the information about the session variable the cookies and much more. Not to mention it also lets you know what extensions are loaded in the server. What extensions are in PHP, I will let you know in my next post.

Keep reading and keep tuned in!

Thanks!