<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:refactormycode.com,2007:users106</id>
  <link type="application/atom+xml" href="http://refactormycode.com/users/106" rel="self"/>
  <title>techietim</title>
  <updated>Mon Mar 24 00:00:15 +0000 2008</updated>
  <entry>
    <id>tag:refactormycode.com,2007:Code265</id>
    <published>2008-03-24T00:00:15+00:00</published>
    <updated>2008-06-11T09:39:22+00:00</updated>
    <title>[PHP] Command-Line TicTacToe</title>
    <content type="html">&lt;p&gt;Just wondering if there are any ways to make this smaller.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php
$std = fopen(&amp;quot;php://stdin&amp;quot;, &amp;quot;r&amp;quot;);
echo &amp;quot;TICTACTOE\n\n\n\n&amp;quot;;
function letsSeeUm($taken){
  foreach(range(1, 9) as $i) ${&amp;quot;s&amp;quot; . $i} = array_key_exists($i, $taken) ? $taken[$i]:&amp;quot; &amp;quot;;
  echo &amp;quot;   +   +   \n $s1 + $s2 + $s3 \n   +   +   \n+++++++++++\n   +   +   \n $s4 + $s5 + $s6 \n   +   +   \n+++++++++++\n   +   +   \n $s7 + $s8 + $s9 \n   +   +   \n\n&amp;quot;;
}
function check($squ, $em = &amp;quot;x&amp;quot;){
  if(($squ[1] == $em &amp;amp;&amp;amp; $squ[2] == $em &amp;amp;&amp;amp; $squ[3] == $em) || ($squ[4] == $em &amp;amp;&amp;amp; $squ[5] == $em &amp;amp;&amp;amp; $squ[6] == $em) || ($squ[7] == $em &amp;amp;&amp;amp; $squ[8] == $em &amp;amp;&amp;amp; $squ[9] == $em) || ($squ[1] == $em &amp;amp;&amp;amp; $squ[4] == $em &amp;amp;&amp;amp; $squ[7] == $em) || ($squ[2] == $em &amp;amp;&amp;amp; $squ[5] == $em &amp;amp;&amp;amp; $squ[8] == $em) || ($squ[3] == $em &amp;amp;&amp;amp; $squ[6] == $em &amp;amp;&amp;amp; $squ[9] == $em) || ($squ[1] == $em &amp;amp;&amp;amp; $squ[5] == $em &amp;amp;&amp;amp; $squ[9] == $em) || ($squ[3] == $em &amp;amp;&amp;amp; $squ[5] == $em &amp;amp;&amp;amp; $squ[7] == $em)) return true;
  return false;
}
$squares = array();
$player = 1;
while(1){
  echo str_repeat(&amp;quot;\n&amp;quot;, 100);
  letsSeeUm($squares);
  echo &amp;quot;Player $player&amp;gt; &amp;quot;;
  $input = (int) fgets($std);
  if(!array_key_exists($input, $squares) &amp;amp;&amp;amp; in_array($input, range(1, 9))){
    $squares[$input] = ($player == 1) ? &amp;quot;x&amp;quot;:&amp;quot;o&amp;quot;;
    if(check($squares) || check($squares, &amp;quot;o&amp;quot;)){
      echo str_repeat(&amp;quot;\n&amp;quot;, 100);
      letsSeeUm($squares);
      echo &amp;quot;\nPlayer $player Wins!&amp;quot;;
      die;
    }
    if(count($squares) == 9){
      echo str_repeat(&amp;quot;\n&amp;quot;, 100);
      letsSeeUm($squares);    
      echo &amp;quot;\nDraw!&amp;quot;;
      die;
    }
    $player = $player == 1 ? 2:1;
  }
}&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/265-command-line-tictactoe" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor1770</id>
    <published>2008-01-26T17:29:42+00:00</published>
    <title>[PHP] On Eval encoded file decoder</title>
    <content type="html">&lt;p&gt;Is there an example script that this would work on?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/218-eval-encoded-file-decoder/refactors/1770" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor1122</id>
    <published>2007-12-12T23:40:53+00:00</published>
    <title>[PHP] On Log Referer, Excluding...</title>
    <content type="html">

&lt;pre&gt;&amp;lt;?php
$domains = array();
$ref = $_SERVER['HTTP_REFERER'];
if (substr($ref, 0, 33) != &amp;quot;http://www.thegrandtournament.com&amp;quot;){
	$myFile = &amp;quot;log.txt&amp;quot;;
    $parsed = parse_url($ref);
    if(!in_array($ref, array_map(&amp;quot;trim&amp;quot;, file($myFile))) &amp;amp;&amp;amp; !in_array($parsed['host'], $domains)){
	    $fh = fopen($myFile, 'a') or die(&amp;quot;can't open file&amp;quot;);
	    $stringData = $ref.&amp;quot;\n&amp;quot;;
	    fwrite($fh, $stringData);
	    fclose($fh);
    }
}&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/183-log-referer-excluding/refactors/1122" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor1032</id>
    <published>2007-12-07T19:31:50+00:00</published>
    <title>[PHP] On Output div block with PHP conditional statement</title>
    <content type="html">&lt;p&gt;This is one way to shorten it&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php 
echo (the_ID() == 8) ? '&amp;lt;div id=&amp;quot;menu_show&amp;quot; class=&amp;quot;slideshow&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://example.org/image.gif&amp;quot; alt=&amp;quot;A picture&amp;quot; width=&amp;quot;748&amp;quot; height=&amp;quot;245&amp;quot; /&amp;gt;&amp;lt;/div&amp;gt;':'&amp;lt;div class=&amp;quot;header&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;';
?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/175-output-div-block-with-php-conditional-statement/refactors/1032" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor980</id>
    <published>2007-11-28T10:51:06+00:00</published>
    <title>[PHP] On dynamic select box</title>
    <content type="html">&lt;p&gt;This should do it.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php
echo '&amp;lt;select name=&amp;quot;options&amp;quot;&amp;gt;';
foreach(array(&amp;quot;option1&amp;quot;, &amp;quot;option2&amp;quot;, &amp;quot;option3&amp;quot;) as $i){
    $select = ($_GET['options'] == $i) ? ' selected=&amp;quot;selected&amp;quot;':'';
    echo '&amp;lt;option value=&amp;quot;'.$i.'&amp;quot;'.$select.'&amp;gt;'.$i.'&amp;lt;/option&amp;gt;';
}
echo '&amp;lt;/select&amp;gt;';&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/166-dynamic-select-box/refactors/980" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor714</id>
    <published>2007-11-04T14:16:22+00:00</published>
    <title>[PHP] On Message system IP-ban</title>
    <content type="html">&lt;p&gt;1) You should using true and false as booleans, not strings
&lt;br /&gt;2) It should be a double equal sign (==), not a single, in the if statements.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/132-message-system-ip-ban/refactors/714" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor488</id>
    <published>2007-10-20T14:10:57+00:00</published>
    <title>[PHP] On FTPSocket</title>
    <content type="html">&lt;p&gt;That's pretty good. You should post that up on:
&lt;br /&gt;&lt;a href="http://php.net/ftp" target="_blank"&gt;http://php.net/ftp&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/72-ftpsocket/refactors/488" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor413</id>
    <published>2007-10-13T00:50:01+00:00</published>
    <title>[PHP] On making user html input secure</title>
    <content type="html">&lt;p&gt;That cleans all of the $_POST values. Example usage below.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php
if(isset($_POST['asdasd'])){
foreach($_POST as $pname =&amp;gt; $pvalue){
    $_POST[$pname] = str_replace(array(&amp;quot;\\&amp;quot;, '\\'), array(&amp;quot;\'&amp;quot;, '\&amp;quot;'), htmlspecialchars(trim($pvalue)));
}
print_r($_POST);
}else{
?&amp;gt;
&amp;lt;form action=&amp;quot;&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;
&amp;lt;input name=&amp;quot;asdasd222&amp;quot; value=&amp;quot;ssssssssssss&amp;quot; /&amp;gt;
&amp;lt;input name=&amp;quot;asdasdas&amp;quot; value=&amp;quot;ssssq42345'''&amp;quot; /&amp;gt;
&amp;lt;input name=&amp;quot;asdasdastt&amp;quot; value=&amp;quot;ssssq42345'''&amp;quot; /&amp;gt;
&amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;asdasd&amp;quot; value=&amp;quot;test&amp;quot; /&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;?php
}&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/80-making-user-input-secure/refactors/413" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor411</id>
    <published>2007-10-12T23:32:50+00:00</published>
    <title>[PHP] On making user html input secure</title>
    <content type="html">&lt;p&gt;Try this.&lt;/p&gt;

&lt;pre&gt;foreach($_POST as $pname =&amp;gt; $pvalue){
    $_POST[$pname] = str_replace(array(&amp;quot;\\&amp;quot;, '\\'), array(&amp;quot;\'&amp;quot;, '\&amp;quot;'), htmlspecialchars(trim($pvalue)));
}&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/80-making-user-input-secure/refactors/411" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor280</id>
    <published>2007-10-04T14:36:57+00:00</published>
    <title>[PHP] On PHP Get</title>
    <content type="html">&lt;p&gt;Check this out:
&lt;br /&gt;&lt;a href="http://refactormycode.com/codes/42-content-page-include" target="_blank"&gt;http://refactormycode.com/codes/42-content-page-include&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/60-php-get/refactors/280" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor174</id>
    <published>2007-10-01T16:55:15+00:00</published>
    <title>[PHP] On Content Page Include</title>
    <content type="html">&lt;p&gt;This should work. I added the in_array so they can only include certain things.&lt;/p&gt;

&lt;pre&gt;&amp;lt;?
$page = $_GET['page'];
$pages = array(&amp;quot;news&amp;quot;, &amp;quot;about&amp;quot;);
if(in_array($page, $pages)){
include($page.&amp;quot;.php&amp;quot;);
}
?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>techietim</name>
      <email>timothy.andrew.cooper@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/42-content-page-include/refactors/174" rel="alternate"/>
  </entry>
</feed>
