WTF *Nix

Just another *nix Blog

Archive for the ‘PHP’ Category

PHP Contact Form Freebie

Apr-29-2010 By WTF *Nix

I’ve had many people asking and requesting of me to provide them a PHP Contact Us form, well here you go… Hope this helps someone out. Just whipped this up for the newbies. If you got a better way to doing this for the newbies feel free to share as well :)

< ?php

if(!$_POST) exit;

$email = $_POST['email'];

if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{

$values = array ('name','email','phone','concerning','message');
$required = array('name','email','message');

$your_email = "james@example.com";
$email_subject = "New Message";
$email_content = "new message:\n";

foreach($values as $value){
if(in_array($value,$required)){
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
$email_content .= $value.': '.$_POST[$value]."\n";
}
}

if(mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

PHP MySQL Functions

Apr-23-2010 By WTF *Nix

MySQL Functions for PHP

mysql_affected_rows — Get number of affected rows in previous MySQL operation

mysql_client_encoding — Returns the name of the character set

mysql_close — Close MySQL connection

mysql_connect — Open a connection to a MySQL Server

mysql_create_db — Create a MySQL database

mysql_data_seek — Move internal result pointer

mysql_db_name — Get result data

mysql_db_query — Send a MySQL query

mysql_drop_db — Drop (delete) a MySQL database

mysql_errno — Returns the numerical value of the error message from previous MySQL operation

mysql_error — Returns the text of the error message from previous MySQL operation

mysql_escape_string — Escapes a string for use in a mysql_query

mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

mysql_fetch_assoc — Fetch a result row as an associative array

mysql_fetch_field — Get column information from a result and return as an object

mysql_fetch_lengths — Get the length of each output in a result

mysql_fetch_object — Fetch a result row as an object

mysql_fetch_row — Get a result row as an enumerated array

mysql_field_flags — Get the flags associated with the specified field in a result

mysql_field_len — Returns the length of the specified field

mysql_field_name — Get the name of the specified field in a result

mysql_field_seek — Set result pointer to a specified field offset

mysql_field_table — Get name of the table the specified field is in

mysql_field_type — Get the type of the specified field in a result

mysql_free_result — Free result memory

mysql_get_client_info — Get MySQL client info

mysql_get_host_info — Get MySQL host info

mysql_get_proto_info — Get MySQL protocol info

mysql_get_server_info — Get MySQL server info

mysql_info — Get information about the most recent query

mysql_insert_id — Get the ID generated in the last query

mysql_list_dbs — List databases available on a MySQL server

mysql_list_fields — List MySQL table fields

mysql_list_processes — List MySQL processes

mysql_list_tables — List tables in a MySQL database

mysql_num_fields — Get number of fields in result

mysql_num_rows — Get number of rows in result

mysql_pconnect — Open a persistent connection to a MySQL server

mysql_ping — Ping a server connection or reconnect if there is no connection

mysql_query — Send a MySQL query

mysql_real_escape_string — Escapes special characters in a string for use in a SQL statement

mysql_result — Get result data

mysql_select_db — Select a MySQL database

mysql_set_charset — Sets the client character set

mysql_stat — Get current system status

mysql_tablename — Get table name of field

mysql_thread_id — Return the current thread ID

mysql_unbuffered_query — Send an SQL query to MySQL without fetching and buffering the result rows.

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

PHP rand Function

Apr-23-2010 By WTF *Nix

Function: rand — Generate a random integer

Description

int rand ( void )

int rand ( int $min , int $max )

If called without the optional min , max arguments rand() returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 5 and 15 (inclusive), for example, use rand(5, 15).

Note: On some platforms (such as Windows), getrandmax() is only 32768. If you require a range larger than 32768, specifying min and max will allow you to create a range larger than this, or consider using mt_rand() instead.

Parameters

min

The lowest value to return (default: 0)

max

The highest value to return (default: getrandmax())

Return Values

A pseudo random value between min (or 0) and max (or getrandmax(), inclusive).

Changelog

Version Description

4.2.0 The random number generator is seeded automatically.

Examples

Example #1 rand() example

< ?php

echo rand() . "\n";

echo rand() . "\n";

echo rand(5, 15);
?>

The above example will output something similar to:

7771

22264

11

See Also

srand() – Seed the random number generator

getrandmax() – Show largest possible random value

mt_rand() – Generate a better random value

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

Codepress and Google Chrome

Mar-31-2010 By WTF *Nix

I was sitting here trying to figure out what I did wrong with codepress within my personal CMS platform… However I use this part within my CMS Platfom to modify the site’s theme, CSS and other web files (Along with the PHP files…) So if you have a Google Chrome and Codepress UGLY look, here’s your fix:

Open up your codepress.html file, and then change the following line of  JavaScript code:

else if(ua.match(‘KHTML’)) engine = ‘khtml’;

to:

else if(ua.match(‘KHTML’)) engine = ‘gecko’;

This will bring everything back as you need to view it. See below :)

(Click to make bigger…)

Chrome CodePress Fix

Hope this helps someone out :)

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

TinyURL… How about BigURL!

Dec-30-2009 By WTF *Nix

As women say bigger the better and more filling… Well some of us don’t have that problem, however in this aspect this guy that’s using my Base62 algo and put it to GOOD use…

Sort of like Viagra on Steriods…

Check it out for yourself: http://ohidunnoitsoneofthosereallylongandhardtofriggintypedomainnames.com/

This has to be the bomb, I’m going to start using this site for the fact of “Bigger is better”

So I had to go test it out for http://www.wtfnix.com/ and this is what I get:

http://www.ohidunnoitsoneofthosereallylongandhardtofriggintypedomainnames.com/something/whatever/dot/whothehellknows/1d/youwillnotbelievethis

Gotta love it huh? So… WTF Get’r Done! Go get yourself an extension done properly on your domain name ;-)

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg