Archive for Code

Troubleshooting PHP Warning: Cannot modify header information – headers already sent

Code, Hack on May 15th, 2012 No Comments

Add the following code to the top of your page:  PHP |  copy code |? 1<?php ob_start(); ?> And add this code to the bottom of your page:  PHP |  copy code |? 1<?php ob_flush(); ?>

Tags: , , , , , , ,

How to Query a Database or String for Specific Word(s)

Code, Hack on April 30th, 2012 Comments Off

Query from database  PHP |  copy code |? 1<?php $query = ‘SELECT * FROM table WHERE field LIKE %variable%’ ?> Query from string  PHP |  copy code |? 12<?php3$statement = ‘Hello, how are you doing today?’;4//Checks string for the word "are"5$query = ‘if (strpos($statement,’are’) !== false) {6 echo ‘true’;7}8?>

Tags: , , , ,

Export MySQL to Excel Using PHP

Code, Hack on February 22nd, 2012 Comments Off

The code below will export every column name and value from your database into an excel document. Note: Delete the line spaces if you receive a parse error.  PHP |  copy code |? 01<?php02/*******EDIT LINES 3-8*******/03$DB_Server = "localhost"; //MySQL Server 04$DB_Username = "username"; //MySQL Username 05$DB_Password = "password"; //MySQL Password 06$DB_DBName = "databasename"; //MySQL Database Name 07$DB_TBLName = "tablename"; //MySQL [...]

Tags: , , ,

Block IP Range using Wildcard with PHP

Code, Hack on October 17th, 2011 No Comments

 PHP |  copy code |? 01// array’s of banned IP addresses02$bannedIP = array("^10.999.00.*", "^99.88.77.*", "192.168.0.1", "^66.77.*.*");03if(in_array($_SERVER[’REMOTE_ADDR’],$bannedIP)) {04 // this is for exact matches of IP address in array05 header("Location: http://www.domain.com");06 exit();07} else {08 // this is for wild card matches09 foreach($bannedIP as $ip) {10 if(eregi($ip,$_SERVER[’REMOTE_ADDR’])) {11 header("Location: http://www.domain.com");12 exit();13 }14 }15}

Tags: , , ,