Wednesday, April 28, 2010

PHP Authentication Vars

Just a quick one for me to remember:


Get current auth info.  Going to be using this in later code.


PHP's json_decode function works well, unless, of course, you get the JSON from a socket server and forget to trim it.  This kicked my butt for a while yesterday.

Another important one to remember is var_dump (which kept showing up as NULL with json_decode before I started trimming the input).

Monday, April 19, 2010

Something to do with a PHP Directory Listing (Make it an HTML Option on another server)

$fp = fopen('http://whereever/whoever.php','r');

$content = '';

while($line = fgets($fp,4096)) {

        $content = $line;
        echo "\n".$content."\n\n"; }

Quickie PHP Directory Listing

$path = ".";

$dir_handle = @opendir($path) or die("Cannot open directory");

while ($file = readdir($dir_handle)) {

if (($file == ".") || ($file == "..") || ($file == "dropdown.php") || ($file == ".svn") || ($file == "old")) {

echo $file."\n"; }


Thursday, April 8, 2010

Quickie PHP Socket connection

$config = array(

'server' => 'serverName',
'port' => 'portNo' );

$socket = fsockopen($config['server'], $config['port'], $errno, $errstr);

if(!$socket) {

        die("Error on page: ".$errno." ".$errstr); }
//uncomment below if stream blocking is needed.
//stream_set_blocking($socket, 1);
$data .= fread($socket, 4096);

echo $data."\n";


Tuesday, April 6, 2010

Apache MySQL Auth

.htaccess File:

AuthName            "Title of Auth Popup"
AuthType            Basic
AuthUserFile            /dev/null
AuthBasicAuthoritative        Off

Auth_MySQL            On
Auth_MySQL_Password_Table    userTable
Auth_Mysql_Group_Table        userGroups

Auth_MySQL_Username_Field    userName
Auth_MySQL_Password_Field    password
Auth_MySQL_Group_Field        groups
Auth_MySQL_Empty_Passwords    Off
Auth_MySQL_Encryption_Types    Plaintext Crypt_DES MySQL

require                group groupName(s)

Just a MySQL statement I need to remember

select count(distinct userName) from userTracking where timeStamp >= '2010-03-30' AND status LIKE '%Logged into $%';

counts unique userNames from userTracking between March 30th 2010 and now and looks for "Logged into $" in the status field.

and even better:

SELECT COUNT(DISTINCT userName) FROM userTracking WHERE timeStamp >= DATE(NOW()) - INTERVAL 11 DAY + INTERVAL 10 HOUR AND timeStamp <= DATE(NOW()) - INTERVAL 0 DAY + INTERVAL 10 HOUR AND status LIKE '%Logged into $%';

between 11 days ago at 10am and today at 10am.

Delete MySQL Records Older Than *BLAH*




Thanks to:

Monday, April 5, 2010

My Reason to Despise Java

I understand it's a great language. Portable, (supposedly) easy to write. Also takes up a TON of file handlers on Linux. Quick fix below:

ADD: session required

ADD: fs.file-max = 1137875
then RUN: sysctl -p

* soft nofile 131070
* hard nofile 131070
* soft nproc 25000
* hard nproc 65000

(This is for Ubuntu, and MY settings....yours may be different).

Friday, April 2, 2010

PHP Code for XML

At my current job I'm writing a lot of PHP scripts to take the load off of our programmers and pass that load to our art dept. Much of the data gets passed as static XML files, which I'm converting to dynamic XML from MySQL via PHP, using the following code:


//The big one to make PHP spit it out as XML

header("Content-type: text/xml");



$sql_query="SELECT * FROM configTable";


Not the cleanest code, I know, but it works.


This blog is essentially a dumping ground for programming and thought snippets that I consider useful or entertaining. I want a central area that I can come to when I run into a problem I've solved before, but can't remember how I did it (easily done with 15+ years in tech). If you're reading these, I hope they help you as well.