<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users707</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/707" rel="self"/>
  <title>Ishkur</title>
  <updated>Sat Oct 11 02:36:31 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor54779</id>
    <published>2008-10-11T02:36:31-07:00</published>
    <title>[Ruby] On brute-force password cracker</title>
    <content type="html">&lt;p&gt;Hmmm, I certainly can't speak for everyone here (nor do I care to, for that matter), but um... wtfm8?&lt;/p&gt;

&lt;p&gt;I just don't see that as the greatest idea. And also, why Ruby?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/531-brute-force-password-cracker/refactors/54779" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor17242</id>
    <published>2008-09-14T00:19:11-07:00</published>
    <title>[Java] On Java IRC Bot</title>
    <content type="html">&lt;p&gt;I decided to refactor it myself and ended up recoding it. I took a slightly different approach this second time. I created a class for the Bot and its functions, and then implemented it in the Main class and controlled the Bot functionality with Regex.&lt;/p&gt;

&lt;pre&gt;## Main.java 
package ircbot;

/**
 * JavaBot (version 1.2)
 * 
 * MIT License, dydx (Josh Sandlin) &amp;lt;dydx@thenullbyte.org&amp;gt;
 *   
 */

import java.io.*;
import java.net.*;
import java.util.regex.*;
import java.util.Date;
import java.util.Random;

public class Main
{   
    public static void main( String[] args ) throws IOException
    {
        //connection variables
        String server = args[0]; //irc.snappeh.com
        String nick = args[1]; //JavaBot
        String address = &amp;quot;thenullbyte.org&amp;quot;;
        String channel = &amp;quot;#&amp;quot;+args[2]; //#enigmagroup
        int port = 6667;
        
        //for security
        String owner = &amp;quot;dydx&amp;quot;;
        
        try {
            
            //our socket we're connected with
            Socket irc = new Socket( server, port );
            //out output stream
            BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( irc.getOutputStream() ) );
            //our input stream
            BufferedReader br = new BufferedReader( new InputStreamReader( irc.getInputStream() ) );
            
            //create a new instance of the JavaBot
            Bot JavaBot = new Bot( bw, channel);
            
            //authenticate the JavaBot with the server
            JavaBot.login( nick, address );
            
            String currLine = null;
            while( ( currLine = br.readLine() ) != null )
            {
                
                //compile a regex to check and see if the person calling commands is the owner
                Pattern checkOwner = Pattern.compile( &amp;quot;^:&amp;quot;+owner, Pattern.CASE_INSENSITIVE );
                Matcher ownership = checkOwner.matcher( currLine );
                
                //constantly check for PING's, if the bot sees one, it replies with a PONG
                Pattern pingRegex = Pattern.compile( &amp;quot;^PING&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher ping = pingRegex.matcher( currLine );
                if( ping.find() )
                {
                    JavaBot.pong();
                }
                
                //check to see if the owner has given the !exit command
                Pattern exitRegex = Pattern.compile( &amp;quot;!exit&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher exit = exitRegex.matcher( currLine );
                if( exit.find() &amp;amp;&amp;amp; ownership.find() )
                {
                    JavaBot.say( &amp;quot;I'm tired, bye yall&amp;quot; );
                    JavaBot.quit();
                }
                
                //parts one room and joins another, gives a nice little going away speech as well
                Pattern joinRegex = Pattern.compile( &amp;quot;!join&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher join = joinRegex.matcher( currLine );
                if( join.find() &amp;amp;&amp;amp; ownership.find() )
                {
                    String[] token = currLine.split( &amp;quot; &amp;quot; );
                    JavaBot.say( &amp;quot;I'm going to go over to &amp;quot; + token[4] + &amp;quot; and see what they're up to over there. Cya.&amp;quot; );
                    JavaBot.part();
                    channel = token[4];
                    JavaBot.join( channel );
                    JavaBot.say( &amp;quot;Hey guys!&amp;quot; );
                }
                
                //we should be polite every now and then, this introduces the bot
                Pattern sayhiRegex = Pattern.compile( &amp;quot;!sayhi&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher sayhi = sayhiRegex.matcher( currLine );
                if( sayhi.find() &amp;amp;&amp;amp; ownership.find() )
                {
                    JavaBot.say( &amp;quot;Hi, I'm a JavaBot. I was written by dydx in Java!&amp;quot; );
                }
                
                //more or less a PoC, just returns the current date/time to the IRC channel
                Pattern timeRegex = Pattern.compile( &amp;quot;!time&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher time = timeRegex.matcher( currLine );
                if( time.find() )
                {
                    Date d = new Date();
                    String message = &amp;quot;The date is &amp;quot; + d ;
                    JavaBot.say( message );
                }
            }
        } catch ( UnknownHostException e ) {
            System.err.println( &amp;quot;No such host&amp;quot; );
        } catch ( IOException e ) {
            System.err.println( &amp;quot;There was an error connecting to the host&amp;quot; );
        } 
    }
}

## Bot.Java
package ircbot;

import java.io.*;

/**
 * The skeleton of the IRC Bot. 
 * 
 * @author dydx
 */
public class Bot
{
    BufferedWriter bw;
    String channel;
    
    /**
     * Bot class constructor, set the defaults for the output stream and the channel
     * @param writer
     * @param chan
     * @param own
     */
    Bot( BufferedWriter writer, String chan )
    {
        bw = writer;
        channel = chan;
    }
    
    /**
     * This is the main part of the bot, it replies to PING's
     * @throws java.io.IOException
     */
    public void pong() throws IOException
    {
        bw.write( &amp;quot;PONG &amp;quot; + channel + &amp;quot;\n&amp;quot; );
        bw.flush();
    }
    
    /**
     * General purpose method for inputting into the channel at hand
     * @param message
     * @throws java.io.IOException
     */
    public void say( String message ) throws IOException
    {
        bw.write( &amp;quot;PRIVMSG &amp;quot; + channel + &amp;quot; :&amp;quot; + message + &amp;quot;\n&amp;quot; );
        bw.flush();
    }
    
    /**
     * Joins a specified IRC channel and sets this.channel accordingly
     * @param channel
     * @throws java.io.IOException
     */
    public void join( String chan ) throws IOException
    {
        bw.write( &amp;quot;JOIN &amp;quot; + chan + &amp;quot;\n&amp;quot; );
        bw.flush();
        
        //we're doing this so that there's no confusion
        //as to which channel the bot is in
        channel = chan;
    }
    
    /**
     * Leave the curent channel
     * @throws java.io.IOException
     */
    public void part() throws IOException
    {
        bw.write( &amp;quot;PART &amp;quot; + channel + &amp;quot;\n&amp;quot; );
        bw.flush();
    }
    
    /**
     * Quit the current IRC session
     * @param reason
     * @throws java.io.IOException
     */
    public void quit() throws IOException
    {
        bw.write( &amp;quot;QUIT &amp;quot; + channel + &amp;quot;\n&amp;quot; );
        bw.flush();
    }
    
    /**
     * Class method used to authenticate the Bot with the IRC server
     * @param nick
     * @param address
     * @throws java.io.IOException
     */
    public void login( String nick, String address ) throws IOException
    {
        bw.write( &amp;quot;NICK &amp;quot; + nick + &amp;quot;\n&amp;quot; );
        bw.write( &amp;quot;USER &amp;quot; + nick + &amp;quot; &amp;quot; + address + &amp;quot;: Java Bot\n&amp;quot; );
        bw.flush();
        
        bw.write( &amp;quot;JOIN &amp;quot; + channel + &amp;quot;\n&amp;quot; );
        bw.flush();
    }
    
    /**
     * General method for yelling at users, might not need to use it after all
     * @param message
     * @throws java.io.IOException
     */
    public void yell( String message ) throws IOException
    {
        say( message );
    }
    
    /**
     * Will eventually be used to search for crap on Wikipedia
     * @throws java.io.IOException
     */
    public void wiki() throws IOException
    {
        say( &amp;quot;Sorry folks, but that feature isn't working just yet.&amp;quot; );
    }
}
&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/490-java-irc-bot/refactors/17242" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code490</id>
    <published>2008-09-13T06:04:15-07:00</published>
    <updated>2008-11-04T11:46:39-08:00</updated>
    <title>[Java] Java IRC Bot</title>
    <content type="html">&lt;p&gt;I've been working on this for a few days, and I finally have it to where it actually works like I want it to. I'm new to Java, so I know this isn't the best way I could have coded it, and I'm curious to see how anyone would improve upon it.&lt;/p&gt;

&lt;pre&gt;package ircbot;

/**
 * JavaBot (version 1.2)
 * 
 * MIT License, dydx (Josh Sandlin) &amp;lt;dydx@thenullbyte.org&amp;gt;
 *  
 */

import java.io.*;
import java.net.*;
import java.util.regex.*;
import java.util.Date;

public class Main
{   
    public static void main( String[] args ) throws IOException
    {
        //connection variables
        String server = &amp;quot;irc.snappeh.com&amp;quot;;
        String nick = &amp;quot;JavaBot&amp;quot;;
        String login = &amp;quot;JavaBot&amp;quot;;
        String channel = &amp;quot;#bots&amp;quot;;
        int port = 6667;
        
        //for security
        String owner = &amp;quot;dydx&amp;quot;;
        
        try {
            
            //our socket we're connected with
            Socket irc = new Socket( server, port );
            //out output stream
            BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( irc.getOutputStream() ) );
            //our input stream
            BufferedReader br = new BufferedReader( new InputStreamReader( irc.getInputStream() ) );
            
            //authenticate with the server
            bw.write( &amp;quot;NICK &amp;quot; + nick + &amp;quot;\n&amp;quot; );
            bw.write( &amp;quot;USER &amp;quot; + login + &amp;quot; thenullbyte.org JB: Java Bot\n&amp;quot; );
            bw.flush();
            
            //join a channel
            bw.write( &amp;quot;JOIN &amp;quot; + channel + &amp;quot;\n&amp;quot; );
            bw.write( &amp;quot;PRIVMSG &amp;quot; + channel + &amp;quot; :Whats up everybody?\n&amp;quot; );
            bw.flush();
            System.out.println( &amp;quot;Successfully connected to IRC&amp;quot; );
            
            String currLine = null;
            while( ( currLine = br.readLine() ) != null )
            {
                //checks for PING, if one is found; return a PONG
                Pattern pingRegex = Pattern.compile( &amp;quot;^PING&amp;quot;, Pattern.CASE_INSENSITIVE ); 
                Matcher ping = pingRegex.matcher( currLine );
                if( ping.find() )
                {
                    bw.write( &amp;quot;PONG &amp;quot; + channel + &amp;quot;\n&amp;quot; );
                    bw.flush();
                }
                
                
                //check for ownership
                Pattern checkOwner = Pattern.compile( &amp;quot;^:&amp;quot;+owner, Pattern.CASE_INSENSITIVE );
                Matcher ownership = checkOwner.matcher( currLine );
                
                //!exit - quit current irc room
                Pattern exitRegex = Pattern.compile( &amp;quot;!exit&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher exit = exitRegex.matcher( currLine );
                if( exit.find() &amp;amp;&amp;amp; ownership.find() )
                {
                    bw.write( &amp;quot;PRIVMSG &amp;quot; + channel + &amp;quot; :Bye Bye\n&amp;quot; );
                    bw.write( &amp;quot;PART &amp;quot; + channel + &amp;quot;\n&amp;quot; );
                    bw.flush();
                    irc.close();
                }
                
                //!time - return current time
                Pattern timeRegex = Pattern.compile( &amp;quot;!time&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher time = timeRegex.matcher( currLine );
                if( time.find()  &amp;amp;&amp;amp; ownership.find() )
                {
                    Date d = new Date();
                    bw.write( &amp;quot;PRIVMSG &amp;quot; + channel + &amp;quot; :&amp;quot; + d +&amp;quot;\n&amp;quot; );
                    bw.flush();
                }
                
                //!sayhi - shows a little message saying hello
                Pattern helloRegex = Pattern.compile( &amp;quot;!sayhi&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher hello = helloRegex.matcher( currLine );
                if( hello.find()  &amp;amp;&amp;amp; ownership.find() )
                {
                    bw.write( &amp;quot;PRIVMSG &amp;quot; + channel + &amp;quot; :Hello, I'm a JavaBot. I was coded by dydx in Java!\n&amp;quot;);
                    bw.flush();
                }
                
                //!join &amp;lt;room&amp;gt; - changes to a new room and sets the variables accordingly
                Pattern joinRegex = Pattern.compile( &amp;quot;!join&amp;quot;, Pattern.CASE_INSENSITIVE );
                Matcher join = joinRegex.matcher( currLine );
                if( join.find()  &amp;amp;&amp;amp; ownership.find() )
                {
                    String[] token = currLine.split( &amp;quot; &amp;quot; );
                    bw.write( &amp;quot;PRIVMSG &amp;quot; + channel + &amp;quot; :Im going over to &amp;quot; + token[4] + &amp;quot;\n&amp;quot; );
                    bw.write( &amp;quot;PART &amp;quot; + channel + &amp;quot;\n&amp;quot; );
                    channel = token[4];
                    bw.write( &amp;quot;JOIN &amp;quot; + channel + &amp;quot;\n&amp;quot; );
                    bw.flush();
                }
            }
        } catch ( UnknownHostException e ) {
            System.err.println( &amp;quot;No such host&amp;quot; );
        } catch ( IOException e ) {
            System.err.println( &amp;quot;There was an error connecting to the host&amp;quot; );
        } 
    }
}&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/490-java-irc-bot" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code489</id>
    <published>2008-09-11T04:07:46-07:00</published>
    <updated>2008-10-25T13:25:34-07:00</updated>
    <title>[Java] Processing / Java</title>
    <content type="html">&lt;p&gt;I'm trying to move out of Processing's PDE and into a more standard IDE (NetBeans). So far everything has gone fairly well. Importing the core.jar is about all it takes to get going with Processing in a normal Java environment. My issue lies with a if...else in my draw() method.&lt;/p&gt;

&lt;p&gt;What my script does is plot an ellipse along an increasing orbit. Depending on what you set as the orbit gain, the speed, and if you have acceleration, it can turn out at somewhat interesting. &lt;/p&gt;

&lt;p&gt;I tried to add coloration to the script.
&lt;br /&gt;if( diameter == 5 ) fill( green );
&lt;br /&gt;if( diameter == 10) fill( pink );
&lt;br /&gt;etc.&lt;/p&gt;

&lt;p&gt;In the PDE this type of thing works fine, but for some reason regular old Java doesnt like this. I don't get any errors, I just dont get anything at all. If I could see how the PDE interprets what I put in there, then I might be able to figure out what I'm doing wrong... but until I can figure that out, does anyone have any ideas?&lt;/p&gt;

&lt;pre&gt;package spirals;
import processing.core.*;

public class Main extends PApplet
{
    float x;
    float y;
    int i = 1;
    int dia = 1;
    
    float angle = 0.0f;
    float speed = 0.05f;
    float orbit = 0f;
    
    //color palette
    int gray = 0x0444444;
    int blue = 0x07cb5f7;
    int pink = 0x0f77cb5;
    int green = 0x0b5f77c;
    
    public Main(){}
    
    public static void main( String[] args )
    {
        PApplet.main( new String[] { &amp;quot;spirals.Main&amp;quot; } );
    }
    
    public void setup()
    {
        background( gray );
        size( 400, 400 );
        fill( gray );
        stroke( gray );
        strokeWeight( 4 );
        smooth();
    }
    
    public void draw()
    {   
        //take the mod of i and decide what to
        //set as the fill color
        if( i % 11 == 0 )
            fill( green );
        else if( i % 13 == 0 )
            fill( blue );
        else if( i % 15 == 0 )
            fill( pink );
        else if( i % 17 == 0 )
            fill( gray );
        
        orbit += 0.1f; //ever so slightly increase the orbit
        //speed += 0.00001f; acceleration
        angle += speed % ( width * height );
        
        float sinval = sin( angle );
        float cosval = cos( angle );
        
        //calculate the (x, y) to produce an orbit
        x = ( width / 2 ) + ( cosval * orbit );
        y = ( height / 2 ) + ( sinval * orbit );
        
        dia %= 11; //keep the diameter within bounds.
        ellipse( x, y, dia, dia );
        dia++;
        i++;
    }
}
&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/489-processing-java" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15618</id>
    <published>2008-08-24T04:01:00-07:00</published>
    <title>[PHP] On model loader</title>
    <content type="html">&lt;p&gt;Very interesting ways of going about this, but I think I like the __autoload() approach a little more. I removed the loop (only because I have but one path I want to specify), but other than that it seems to work perfectly.&lt;/p&gt;

&lt;p&gt;The problem with the other methods is that they mess up the inheritance of the model. getAll() is extended from a parent controller, and so when you simple 'return new $model();', it interferes with that for some reason, but the __autoload() seems to keep my inheritance in tact.&lt;/p&gt;

&lt;p&gt;But still, thanks everyone!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/454-model-loader/refactors/15618" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15519</id>
    <published>2008-08-22T20:07:44-07:00</published>
    <title>[PHP] On model loader</title>
    <content type="html">&lt;p&gt;Wow, that refactoring is nifty. I have PHP 5.2.4 at the moment, and I'm working on installing 5.3. Hopefully I'll get something put together soon. Thanks a million for the input. &lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/454-model-loader/refactors/15519" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code454</id>
    <published>2008-08-21T14:16:51-07:00</published>
    <updated>2008-08-24T04:01:02-07:00</updated>
    <title>[PHP] model loader</title>
    <content type="html">&lt;p&gt;I'm doing a lot of work with BareBonesMVC lately, and I've begun to see a need to add some more meat to it. One of the thing's that I'm trying to add is a method for loading models. The method itself is fairly straight forward, and works, but not the way I would really like for it to.&lt;/p&gt;

&lt;pre&gt;## code
&amp;lt;?php
function loadModel($model)
{
	$exclude = array (
		'.',
		'..',
		'index.html'
	);
	
	$handle = opendir(APPPATH.'models/');
	while(false !== ($files = readdir($handle)))
	{
		if(!in_array($file, $exclude))
			$modelArray[] = $files;
	}
	closedir($handle);
	
	if(in_array($model.EXT, $modelArray))
	{
		require_once(APPPATH.'models/'.$model.EXT);
	} else {
		throw new Exception('Attempting to call unknown Model');
	}
}
?&amp;gt;
## usage
&amp;lt;?php
//...
loadModel('blog');//Load blog model
$posts = blog_model::getRecent;
//...
?&amp;gt;
## what  I really want to be able to do
&amp;lt;?php

	//...
	$blogObject = loadModel('blog'); //assign object to a variable
	$posts = $blogObject::getRecent();
	//...

?&amp;gt;
## sidenotes [plain_text]
So far i've managed to get errors about my use of extraneous double colons,
so im betting that php doesnt let me call methods statically like that. Any
thoughts would be helpful.&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/454-model-loader" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15316</id>
    <published>2008-08-19T18:41:04-07:00</published>
    <title>[PHP] On Universal File Download Class</title>
    <content type="html">&lt;p&gt;In your function 'public function cc_wget_file($url)', you're passing the string through exec(). Thats fine, but PHP allows you to pass cli strings via backticks (&lt;a href="http://www.php.net/language.operators.execution" target="_blank"&gt;http://www.php.net/language.operators.execution&lt;/a&gt;). Might help, might not, ymmv.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/440-universal-file-download-class/refactors/15316" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15029</id>
    <published>2008-08-14T14:54:26-07:00</published>
    <title>[PHP] On Getter and Setter</title>
    <content type="html">&lt;p&gt;Note: the above refactoring doesnt seem to really work, but it does outline an *example* of how to use PHP5's magic methods __set() and __get(). &lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/425-getter-and-setter/refactors/15029" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14504</id>
    <published>2008-08-05T05:39:01-07:00</published>
    <title>[PHP] On MySQL original PHP 5 wrapper class</title>
    <content type="html">&lt;p&gt;I've taken to liking your database wrapper, a lot. Among a few minor tweaks, I've added a method to it that you might (or might not) like, check this out:&lt;/p&gt;

&lt;pre&gt;## getWhere() method [php]
&amp;lt;?php
	/**
	 * $page = page::getWhere(array('PageID' =&amp;gt; 125));
	 */
	protected static function getWhere($class, $table, $where = array())
	{
		if(!self::$dbconnected)
			self::connect();
		$etu = array();
		//process WHERE statement
		$txt_query = 'SELECT * FROM '.$table;
		$i = 0;
		foreach($where as $key =&amp;gt; $value)
		{
			if($i == 0)
				$txt_query .= ' WHERE ';
			else
				$txt_query .= ' AND ';
				
			$txt_value = self::quote_smart($value);
			if(is_numeric($value))
				$txt_query .= &amp;quot;$key = $value&amp;quot;;
			elseif(is_null($value))
				$txt_query .= &amp;quot;$key = NULL&amp;quot;;
			else
				$txt_query .= &amp;quot;$key = '$txt_value'&amp;quot;;
			$i++;
		}
		
		$txt_query .= ';';
		if(($result = @mysql_query($txt_query)) === false)
			throw new Exception('Impossible to retrieve desired items of '.$table);
		while($d = @mysql_fetch_object($result))
		{
			$e = new $class;
			foreach(get_object_vars($d) as $var =&amp;gt; $value)
				$e-&amp;gt;$var = $value;
			//this returns an array, which makes us have to foreach the return.
			//might want to make some sort of checking to see if the result
			//is more than 1 row it returns an array, and if only just 1 row returns,
			//it sets it as a singular object (such as if you were selecting pages
			//from a database with like Categories, you'd need an array to loop through,
			//but if you were selecting a single user, that loop would be an unnecessary 
			//hassle)... something to work on later i guess
			$etu[] = $e;
		}
		return $etu;
	}
?&amp;gt;

## child class usage [php]
&amp;lt;?php

	public static function getWhere($where)
	{
		return parent::getWhere(__CLASS__, self::$_table, $where);
	}

?&amp;gt;

## Final Usage [php]
&amp;lt;?php

//include required files
require_once('inc/classes/db.class.php');
require_once('inc/models/page.class.php');

//some generic scenario where
//you would needa WHERE clause
$login = array(
	'username' =&amp;gt; &amp;quot;$_POST['username']&amp;quot;,
	'password' =&amp;gt; &amp;quot;$_POST['password']&amp;quot;
);

//fetch user records from database
$user = user::getWhere($login);

//...
//process login	
//...

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/416-mysql-original-php-5-wrapper-class/refactors/14504" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14383</id>
    <published>2008-08-02T19:14:22-07:00</published>
    <title>[PHP] On MySQL original PHP 5 wrapper class</title>
    <content type="html">&lt;p&gt;Can you elaborate some more as to why you dont? do you run a custom error handling mechanism, or do you just not handle extraneous errors ?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/416-mysql-original-php-5-wrapper-class/refactors/14383" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14350</id>
    <published>2008-08-02T03:04:08-07:00</published>
    <title>[PHP] On MySQL original PHP 5 wrapper class</title>
    <content type="html">&lt;p&gt;There seem to be a lot of these ideas floating around (myself included), and maybe its just me seeing the light (or lackthereof), but I've started using CoughPHP ORM. But your methods looks rather interesting.&lt;/p&gt;

&lt;p&gt;And as for your disconnect();&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php

	//...
	/**
	 * this refactoring might be asinine,
	 * but I think it's important to cover
	 * your ass just in case. 
	 */
	public static function disconnect()
	{
		if(self::$db_link === false)
			throw new Exception('no connection present');
		@mysql_close(self::$db_link);	
	}
	//...

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/416-mysql-original-php-5-wrapper-class/refactors/14350" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14185</id>
    <published>2008-07-31T06:45:21-07:00</published>
    <title>[PHP] On Object with Field names as resources</title>
    <content type="html">&lt;p&gt;Going with that the previous guy mentioned, I look around at ORM solutions that would fit the bill. Just about everything I could find was entirely oversized and just added so much overhead it was terrifying. So i looked for a more lightweight solution and found some rather good software (&lt;a href="http://coughphp.com/" target="_blank"&gt;http://coughphp.com/&lt;/a&gt;). CoughPHP seems to do what I want decently, so I'm going to see where that gets me. &lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/400-object-with-field-names-as-resources/refactors/14185" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor13980</id>
    <published>2008-07-28T20:16:02-07:00</published>
    <title>[PHP] On Object with Field names as resources</title>
    <content type="html">&lt;p&gt;Sorry, I mixed up my terms. I am trying to map over to an object.&lt;/p&gt;

&lt;p&gt;Below is sort of getting me closer, to where I was aiming at.&lt;/p&gt;

&lt;p&gt;And Prengel, I'll look at that. Thank you.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php

class ParentClass
{
	protected $database;
	protected $tables;
	//...
	
	public function __construct($table)
	{
		//get an instance of my own database class
		//and use it in this one.
		$this-&amp;gt;database = DB::GetInstance();
		
		//set table name to query
		$this-&amp;gt;table = $table;
	}
	
	//...
	//some magic
	//...
}

class User extends ParentClass
{
	public function __construct()
	{
		parent::__construct('users');
	}
}

$bob = new User();
$bob-&amp;gt;username = 'bob';
//...
//insert new row with whatever specs
//i defined with $bob-&amp;gt;[var] = [val].
$bob-&amp;gt;create();

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/400-object-with-field-names-as-resources/refactors/13980" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code400</id>
    <published>2008-07-28T19:35:54-07:00</published>
    <updated>2009-01-09T19:35:00-08:00</updated>
    <title>[PHP] Object with Field names as resources</title>
    <content type="html">&lt;p&gt;What I am trying to do is a little hard to explain, but basically I want to map database fieldnames to an object, corresponding to table name.&lt;/p&gt;

&lt;p&gt;So `users` would be used in a class called Users, etc.&lt;/p&gt;

&lt;p&gt;I've managed to query the database and stick the fieldnames into an associative array with the code below, but how I'm going to create the object is slightly above me right now.&lt;/p&gt;

&lt;p&gt;As of now I have a parent class that im trying to get to handle the querying of field names, and im extending it to create the different classes. &lt;/p&gt;

&lt;pre&gt;## Table [plain_text]
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| user_id  | int(11)     | NO   | PRI | NULL    | auto_increment | 
| username | varchar(20) | YES  |     | NULL    |                | 
| password | varchar(32) | YES  |     | NULL    |                | 
| email    | varchar(50) | YES  |     | NULL    |                | 
+----------+-------------+------+-----+---------+----------------+

## Query [php]
&amp;lt;?php

	$db = mysql_connect('localhost', 'root', 'rootpass');
	mysql_select_db('dname', $db);	
	
	$query = &amp;quot;SHOW COLUMNS FROM users;&amp;quot;;
	$result = mysql_query($query, $db);
	while($row = mysql_fetch_assoc($result))
	{
		$fields[] = $row['Field'];
	}
	var_dump($fields);

?&amp;gt;

## Result Array [plain_text]
array(4) {
  [0]=&amp;gt;
  string(7) &amp;quot;user_id&amp;quot;
  [1]=&amp;gt;
  string(8) &amp;quot;username&amp;quot;
  [2]=&amp;gt;
  string(8) &amp;quot;password&amp;quot;
  [3]=&amp;gt;
  string(5) &amp;quot;email&amp;quot;
}

## Overall Goal [php]
//dynamically made class
class user {
	public $user_id;
	public $username;
	public $password;
	public $email;
}&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/400-object-with-field-names-as-resources" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor13515</id>
    <published>2008-07-22T03:36:44-07:00</published>
    <title>[PHP] On PHP5 Database Clas</title>
    <content type="html">&lt;p&gt;Well if I wanted to go that route I could just as well use PDO and be done with the whole class, but thats not really what I want. And to be completely honest I dont really like Pear, it just feels like there's so much overhead. I just sorta wanted the transactional functions to work.... the child methods themselves work, thats not an issue, but the constructor method is whats killing me.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/391-php5-database-clas/refactors/13515" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code391</id>
    <published>2008-07-21T16:33:50-07:00</published>
    <updated>2008-08-06T21:23:32-07:00</updated>
    <title>[PHP] PHP5 Database Clas</title>
    <content type="html">&lt;p&gt;For the most part, this class does everything I need. I've been updating it to PHP5, and have noticed a really rather big issue with my Transaction support: it simple doesnt work.&lt;/p&gt;

&lt;p&gt;I've explained the issue in comments in the code.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php

class DB {
	
	//connection variables
	protected $dbhost = 'localhost';
	protected $dbuser = 'root';
	protected $dbpass = '';
	protected $dbname = 'dbname';
	
	//normal global resources
	protected $db = null;
	protected static $instance = null;
	
	/**
	 * Singleton pattern for instantiating the DB class
	 */
	public static function GetInstance()
	{
		if(!self::$instance)
		{
			self::$instance = new DB;
		}
		return self::$instance;
	}
	
	protected function __construct()
	{
		if(($db = @mysql_connect($this-&amp;gt;dbhost, $this-&amp;gt;dbuser, $this-&amp;gt;dbpass)) === false)
		{
			trigger_error('There was an error connecting to the server.');
			exit;
		}
		
		if((@mysql_select_db($this-&amp;gt;dbname, $db)) === false)
		{
			trigger_error('There was an error selecting the database.');
			exit;
		}
		$this-&amp;gt;db = $db;
	}
	
	/**
	 * simple method for sanitizing SQL query strings.
	 */
	public function Clean($string)
	{
		if(get_magic_quotes_gpc())
		{
			$string = stripslashes($string);
		}
		return mysql_real_escape_string($string);
	}
	
	/**
	 * DB class method call to the Query child class.
	 * SELECT queries only
	 * Returns an object.
	 */
	public function Query($statement)
	{
		return new Query($statement, $this-&amp;gt;db);
	}
	
	/**
	 * DB class method call to the Execute child class.
	 * INSERT/UPDATE/DELETE queries only
	 * Returns number of rows affected.
	 */
	public function Execute($statement)
	{
		return new Execute($statement, $this-&amp;gt;db);
	}
	
	/**
	 * Used to get the last inserted record
	 */
	public function InsertID()
	{
		return mysql_insert_id($this-&amp;gt;link);
	}
	
	/**
	 * The transactional functions are giving me more of a headache than
	 * I sould care to have. The general idea behind what I want to do
	 * with them is be able to pass an array of SQL queries into one
	 * main method call, which in turn calls its child methods.
	 *
	 * The issue I have with this is that there are instances where I
	 * dont want to base a Commit / Rollback on whether or not the
	 * queries succeed or fail, but perhaps the time of day, or the
	 * privelage level of the user running the queries, etc.
	 */
	public function Transaction($queryArray)
	{
		/**
		 * this method call will return a new instance of the
		 * Transaction CLass. Operations are documented within
		 * the Transaction Class.
		 */
		 return new Transaction($queryArray, $this-&amp;gt;db);
	}
	
	public function __destruct()
	{
		@mysql_close($this-&amp;gt;db);
	}
	
}

/**
 * These are separate classes for the reason that I would like
 * to be able to edit them with as little distruption to the 
 * flow of the parent class as possible. 
 */

/**
 * Query child class. Used for running SELECT queries.
 * Called exclusively by the DB parent class in the Query method
 */
class Query
{
	protected $result;
	
	public function __construct($statement, $link)
	{
		if(($this-&amp;gt;result = mysql_query($statement, $link)) === false)
		{
			trigger_error('There was an error in processing the Query method: '. mysql_error());
			exit;
		}
	}
	
	public function Fetch($class = null)
	{
		return @mysql_fetch_object($this-&amp;gt;result);
	}
	
	public function __destruct()
	{
		@mysql_free_result($this-&amp;gt;result);
	}
}

/**
 * Execute child class. Used for running INSERT/UPDATE/DELETE queries.
 * Called exclusively by the DB parent class in the Execute method
 */
class Execute
{
	public function __construct($statement, $link)
	{
		if((@mysql_query($statement, $link)) == false)
		{
			trigger_error('There was an error processing the Execute method: '. mysql_error());
			exit;
		}
		return @mysql_affected_rows($link);
	}
}

/**
 * Transaction child class. Used for transactional queries.
 * Called exclusively by the DB parent class in the Transaction method
 */
class Transaction
{
	public function __construct($queryArray, $link)
	{
		/**
		 * This is not working at all the way I want it to.
		 * 
		 * Essentially what it is doing, is running the first
		 * query, then basing the Commit / Rollback on the
		 * outcome of that single query. That's no good.
		 *
		 * I can see _why_ its not working, but that doesn't
		 * really help me to fix it. 
		 *
		 * $hold is set to 1 as its starting value, and as
		 * the loop progresses it either changes that or 
		 * doesnt, depending on the outcome. What it seems
		 * to be doing is running it once, and deciding
		 * &amp;quot;Hey! the query worked!, lets commit changes!&amp;quot;.
		 */
		$hold = 1;
		$this-&amp;gt;Begin();
		foreach($queryArray as $query) {
			@mysql_query($query, $link);
			if(@mysql_affected_rows($link) == 0)
			{
				$hold = 0;
			}
		}
		if($hold == 0)
		{
			$this-&amp;gt;Rollback();
			return false;
		} else {
			$this-&amp;gt;Commit();
			return true;
		}
	}
	
	private function Begin()
	{
		@mysql_query('BEGIN', $link);
	}
	
	private function Commit()
	{
		@mysql_query('COMMIT', $link);
	}
	
	private function Rollback()
	{
		@mysql_query('ROLLBACK', $link);
	}
}

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/391-php5-database-clas" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor12872</id>
    <published>2008-07-11T00:46:54-07:00</published>
    <title>[PHP] On Database Class</title>
    <content type="html">&lt;p&gt;I've got a sourceforge project dealing with this same sort of thing. And from my experience in coding that I might be able to offer a few tips on how to make it better.&lt;/p&gt;

&lt;p&gt;1.)Since you're clearly using PHP5 for this, why not go ahead and add access control to the global vars and methods. You dont want just anyone to be able to call out your data anywhere they want. you need a defined entry point and a defined access point.&lt;/p&gt;

&lt;p&gt;2.) going along with that PHP5 thing I was talking about, you can also use the __construct() method to define some of your global vars like the username, the password, the host, and the database name. Doing that will save you a lot of coding work and processing time later.&lt;/p&gt;

&lt;p&gt;3.) A lot of your global vars dont look like they need to be initiated as a global var. try to make them as narrow in scope as possible. &lt;/p&gt;

&lt;p&gt;4.) and just a little (and by little, i mean little) advice on making your loops faster. ++$i is faster than $i++. &lt;/p&gt;

&lt;p&gt;For reference on another way of going about this task, you can look at my DB class: &lt;a href="http://jsandlin.org/null_dbw/source.php" target="_blank"&gt;http://jsandlin.org/null_dbw/source.php&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/356-database-class/refactors/12872" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor12114</id>
    <published>2008-06-29T02:03:14-07:00</published>
    <title>[PHP] On Interfacing Tor with cURL</title>
    <content type="html">&lt;p&gt;Well, what I was going for was being able to set parameters and being able to call them back out later. But thanks, I wasn't aware of that naming convention clash i was doing. I did plan however, on setting some of these methods to be private because a few of them aren't really meant to be set by hand.&lt;/p&gt;

&lt;p&gt;EDIT: I took Joe's advice and redid my code accordingly. I fixed my naming conventions as well as condensed all of my 'get''s into a single method returning an array.&lt;/p&gt;

&lt;p&gt;I also moved all of the cURL into its own method, and I've updated the status of most of the methods and set them to private.&lt;/p&gt;

&lt;p&gt;I have not however, had a chance to test it; though it should work just as before.&lt;/p&gt;

&lt;p&gt;I think that it a little better, but im sure more can be done.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php

/**
 * PHP5 class for interfacing with the Tor network
 * by Josh Sandlin &amp;lt;josh@thenullbyte.org&amp;gt;
 * 
 * Licensed: MIT/X11
 * 
 * NOTE: The proxy host is configurable by the user, 
 * so therefore one i not limited to only the Tor
 * network. The default setting however is to run
 * all data through the Tor/Privoxy network.
 * 
 */

class Tor
{
    private $url;
    private $userAgent;
    private $timeout;
    private $proxy;
    private $vector;
    private $payload;
    private $returnData;

    public function Tor()
    {
        $this-&amp;gt;url = null;
        $this-&amp;gt;userAgent = null;
        $this-&amp;gt;timeout = 300;
        $this-&amp;gt;proxy = '127.0.0.1:9050';
        $this-&amp;gt;vector = null;
        $this-&amp;gt;payload = null;
        $this-&amp;gt;returnData = null;
    }

    private function setUrl($url)
    {
        $this-&amp;gt;url = $url;
    }

    private function setUserAgent()
    {
        //list of browsers
        $agentBrowser = array(
                'Firefox',
                'Safari',
                'Opera',
                'Flock',
                'Internet Explorer',
                'Seamonkey',
                'Konqueror',
                'GoogleBot'
        );
        //list of operating systems
        $agentOS = array(
                'Windows 3.1',
                'Windows 95',
                'Windows 98',
                'Windows 2000',
                'Windows NT',
                'Windows XP',
                'Windows Vista',
                'Redhat Linux',
                'Ubuntu',
                'Fedora',
                'AmigaOS',
                'OS 10.5'
        );
        //randomly generate UserAgent
        $this-&amp;gt;userAgent = $agentBrowser[rand(0,7)].'/'.rand(1,8).'.'.rand(0,9).' (' .$agentOS[rand(0,11)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
    }

    private function setTimeout($timeout)
    {
        $this-&amp;gt;timeout = $timeout;
    }

    public function setProxy($ip, $port)
    {
        $this-&amp;gt;proxy = $ip .&amp;quot;:&amp;quot;. $port;
    }

    private function setVector($vector)
    {
        $this-&amp;gt;vector = $vector;
    }

    private function setCurl()
    {
        $action = curl_init();
        curl_setopt($action, CURLOPT_PROXY, $this-&amp;gt;proxy);
        curl_setopt($action, CURLOPT_URL, $this-&amp;gt;payload);
        curl_setopt($action, CURLOPT_HEADER, 1);
        curl_setopt($action, CURLOPT_USERAGENT, $this-&amp;gt;userAgent);
        curl_setopt($action, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($action, CURLOPT_FOLLOLOCATION, 1);
        curl_setopt($action, CURLOPT_TIMEOUT, $this-&amp;gt;timeout);
        $this-&amp;gt;returnData = curl_exec($action);
        curl_close($action);
    }
    
    private function setPayload()
    {
        $this-&amp;gt;payload = $this-&amp;gt;url . $this-&amp;gt;vector;
    }

    public function launch($url, $vector, $timeout = null)
    {
        //set parameters
        $this-&amp;gt;setUrl($url);
        $this-&amp;gt;setVector($vector);
        $this-&amp;gt;setUserAgent();
            
        //set payload
        $this-&amp;gt;setPayload();
            
        //if a timeout is set in the args, use it
        if(isset($timeout))
        {
            $this-&amp;gt;setTimeout($timeout);
        }
            
        //run cURL action against url
        $this-&amp;gt;setCurl();
    }

    public function getTorData()
    {
        return array(
                'url' =&amp;gt; $this-&amp;gt;url,
                'userAgent' =&amp;gt; $this-&amp;gt;userAgent,
                'timeout' =&amp;gt; $this-&amp;gt;timeout,
                'proxy' =&amp;gt; $this-&amp;gt;proxy,
                'payload' =&amp;gt; $this-&amp;gt;payload,
                'return' =&amp;gt; $this-&amp;gt;returnData
        );
    }
}

?&amp;gt; 
&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/340-interfacing-tor-with-curl/refactors/12114" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code340</id>
    <published>2008-06-28T20:29:39-07:00</published>
    <updated>2012-02-06T21:12:31-08:00</updated>
    <title>[PHP] Interfacing Tor with cURL</title>
    <content type="html">&lt;p&gt;I found a php function that does this, but I didnt like it. So, I recoded it as a class. I'm rather new to classes and OOP, so I'm sure there's a better way I could have gone about this. Any ideas on making my code more efficient will be appreciated.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php

/**
 * PHP Class for interfacing with the Tor Network
 */

class Tor
{
	var $url;
	var $userAgent;
	var $timeout;
	var $host;
	var $vector;
	var $payload;
	var $returnData;

	/**
	 * Tor Clas Constructor
	 */
	function Tor()
	{
		$this-&amp;gt;url = null;
		$this-&amp;gt;userAgent = null;
		$this-&amp;gt;timeout = 300;
		$this-&amp;gt;host = '127.0.0.1:9050';
		$this-&amp;gt;vector = null;
	}

	/**
	 * set url
	 */
	function setUrl($url)
	{
		$this-&amp;gt;url = $url;
	}

	/**
	 * read url
	 */
	function readUrl()
	{
		return $this-&amp;gt;url;
	}

	/**
	 * set useragent
	 */
	function setUserAgent()
	{
		//list of browsers
		$agentBrowser = array(
				'Firefox',
				'Safari',
				'Opera',
				'Flock',
				'Internet Explorer',
				'Seamonkey',
				'Konqueror',
				'GoogleBot'
				);
				//list of operating systems
				$agentOS = array(
				'Windows 3.1',
				'Windows 95',
				'Windows 98',
				'Windows 2000',
				'Windows NT',
				'Windows XP',
				'Windows Vista',
				'Redhat Linux',
				'Ubuntu',
				'Fedora',
				'AmigaOS',
				'OS 10.5'
				);
				//randomly generate UserAgent
				$this-&amp;gt;userAgent = $agentBrowser[rand(0,7)].'/'.rand(1,8).'.'.rand(0,9).' (' .$agentOS[rand(0,11)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
	}

	/**
	 * read useragent
	 */
	function readUserAgent()
	{
		return $this-&amp;gt;userAgent;
	}

	/**
	 * set timeout
	 */
	function setTimeout($timeout)
	{
		$this-&amp;gt;timeout = $timeout;
	}

	/**
	 * read timeout
	 */
	function readTimeout()
	{
		return $this-&amp;gt;timeout;
	}

	/**
	 * set host
	 */
	function setHost($ip, $port)
	{
		$this-&amp;gt;host = $ip . &amp;quot;:&amp;quot; . $port;
	}

	/**
	 * read host
	 */
	function readHost()
	{
		return $this-&amp;gt;host;
	}

	/**
	 * set vector
	 */
	function setVector($vector)
	{
		$this-&amp;gt;vector = $vector;
	}

	/**
	 * read vector
	 */
	function readVector()
	{
		return $this-&amp;gt;vector;
	}

	/**
	 * launch payload
	 */
	function launchPayload()
	{
		//set randomized parameters
		$this-&amp;gt;setUserAgent();
			
		//concatinate url
		$this-&amp;gt;payload = $this-&amp;gt;url . $this-&amp;gt;vector;
			
		//run curl action against url
		$action = curl_init();
		curl_setopt($action, CURLOPT_PROXY, $this-&amp;gt;host);
		curl_setopt($action, CURLOPT_URL, $this-&amp;gt;payload);
		curl_setopt($action, CURLOPT_HEADER, 1);
		curl_setopt($action, CURLOPT_USERAGENT, $this-&amp;gt;userAgent);
		curl_setopt($action, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($action, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($action, CURLOPT_TIMEOUT, $this-&amp;gt;timeout);
		$this-&amp;gt;returnData = curl_exec($action);
		curl_close($action);
	}

	function viewReturn()
	{
		return $this-&amp;gt;returnData;
	}
}

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Ishkur</name>
      <email>joshua.sandlin@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/340-interfacing-tor-with-curl" rel="alternate"/>
  </entry>
</feed>

