Catch the Phillies Phever World Series 2008 Unique Collectibles and T's

Archive for the 'PHP' Category

xhref cmd

Tuesday, December 11th, 2007

heres a cool clip for injecting tiny urls into the address line to pass long string arguments…

Ive nested this in my header include for my header “class” to call…
<?php
if ($cmd!=’login’)
{
?>
<a xhref=”index.php” mce_href=”index.php” title=”<?php echo $msg_adminheader; ?>”><?php echo $msg_adminheader; ?></a> |
<a xhref=”index.php?cmd=settings” mce_href=”index.php?cmd=settings” title=”<?php echo $msg_adminheader2; ?>”><?php echo $msg_adminheader2; ?></a> |
<a xhref=”index.php?cmd=cats” mce_href=”index.php?cmd=cats” title=”<?php echo $msg_adminheader3; ?>”><?php echo $msg_adminheader3; ?></a> |
<a xhref=”index.php?cmd=products” mce_href=”index.php?cmd=products” title=”<?php echo $msg_adminheader4; ?>”><?php echo $msg_adminheader4; ?></a> |
<a xhref=”index.php?cmd=sales” mce_href=”index.php?cmd=sales” title=”<?php echo $msg_adminheader5; ?>”><?php echo $msg_adminheader5; ?></a> |
<a xhref=”index.php?cmd=gift” mce_href=”index.php?cmd=gift” title=”<?php echo $msg_adminheader6; ?>”><?php echo $msg_adminheader6; ?></a> |
<a xhref=”index.php?cmd=search” mce_href=”index.php?cmd=search” title=”<?php echo $msg_adminheader7; ?>”><?php echo $msg_adminheader7; ?></a> |
<a xhref=”index.php?cmd=contact” mce_href=”index.php?cmd=contact” title=”<?php echo $msg_adminheader8; ?>”><?php echo $msg_adminheader8; ?></a> |
<a xhref=”index.php?cmd=tools” mce_href=”index.php?cmd=tools” title=”<?php echo $msg_adminheader9; ?>”><?php echo $msg_adminheader9; ?></a> |
<a xhref=”index.php?cmd=logout” mce_href=”index.php?cmd=logout” title=”<?php echo $msg_adminheader10; ?>”><?php echo $msg_adminheader10; ?></a>
<?php
}
else
{
echo ‘• ‘.$msg_login;
}
?>

Assign Class Values

Tuesday, December 11th, 2007

heres an example of assigning a referenced value to a parameter of a class in PHP
$tpl_products->assign(’VIEW_LARGER’, $msg_userproducts7);

Invoice GUID

Thursday, December 6th, 2007

//=======================================
// FUNCTION: INVOICE_NO()
// Generate invoice number
// Param: 0
//======================================

function invoice_no()

{
return ‘inv_’.date(”m-Y”).’_’.$this->random_data(5,’random’);
}

Add Shipping Snippett

Thursday, December 6th, 2007

//=======================================
// FUNCTION: ADD_SHIPPING()
// Adds shipping to total
// Param: 1
// Added to class CheckOut.inc.php
//======================================

function add_shipping($data)
{

if ($this->shipping>0)
{
return number_format($this->shipping+$data,2);
}
else
{
return $data;
}

}

PayPal trickery

Wednesday, December 5th, 2007

Testing on a live Server tonight, I got thinking and You CAN have two Paypal accounts, one business, and one personal, so you can send money between accounts.

Once you have sent money from one to the other, JUST refund it back so NO payment handling fee(s) get processed.

Ha !

;)

FOLDER_PATH

Wednesday, December 5th, 2007

//—————————————–
// Set path to target project root folder
//—————————————-

define (’FOLDER_PATH’,dirname(__FILE__).’/');

// the single quote forces PHP to accept string as a literal

// next, you can call an include at any depth with this virtual
// project anchor available to set as a path cornerstone like so:

include(FOLDER_PATH.’inc/db_connection.inc.php’);

case cmd

Wednesday, December 5th, 2007

In your index switch statement
spec out a page by incrementing this scenario perpage

case ‘about’:
include(FOLDER_PATH.’inc/header.inc.php’);
$tpl_about =& new MethodHere();
$tpl_about->display(’templates/about.tpl.php’);
include(FOLDER_PATH.’inc/footer.inc.php’);
break; // remember to BREAK ! for strong coding

Then call this file like this:
index.php?cmd=about

PHP Class Repository

Tuesday, December 4th, 2007

That site has some great classes.
http://www.phpclasses.org/

list a directory

Monday, July 16th, 2007

< ?
if ($handle = opendir(‘./images’)) //change to point to your directory
{
while (false !== ($file = readdir($handle)))
{
if ($file != “.” && $file != “..”)
{
echo $file
; //change to match your path
}
}
}
?>

PHP interview QAs

Tuesday, May 22nd, 2007

a good list of questions to ask a programmer in a PHP programmer interview

http://www.techinterviews.com/?p=243

DevWorkflow Worksheet

Wednesday, December 13th, 2006

The following are axioms for what I have defined as a best-of-breed approach Ive discovered on my own… I wanted to write a rules based guide for a development approach to application or web deployed solutions driven by C# or PHP OOP ::

classes are encapsulations

you design methods -as business rules - to manipulate instances of classes

each instance of the class ‘instantiated’ is an object

identify static member variables also known as class variables
– these belng to the class not each object - like class ‘globals’ in a sense

you can also declare static methods which can only manipulate static data…
1) Define All Objects::

Object-oriented software analysis and design are preoccupied with the discovery of classes and the relationships they have to each other.


(Nouns,Verbs, Adjectives&Adverbs)
Some objects can be identified

Nouns::
USD,Yen,Pound Dollar Amount,Currency Value

ActionOperations / Verbs are Methods()::
Deposit, Transact, Charge/Send Money
FirstFile(), NextFile(), LastFile, PreviousFile()

// Budget Directory example ::.

public string [] GetFiles()
{
dirs=System.IO.Directory.GetFiles(”c:\\”);

return dirs;

}

public string GetCurrentFile()
{

return dirs(bookmark);

}

// ——————————————————-
// Method that moves to next file in the list ::.

public void NextFile()
{
bookmark++;

// this ++ saves heap position onto the next ‘row’ of
// data thus returning the next file name.

}

// next, declare the overloaded operator
// that moves to the next file in the specified dir.

public static BudgetDirectory

operator

// include the operator not a Next method…

++ (BudgetDirectory bd)bd.NextFile();

return db;

cool short circuiting huh ! ;)

some verbs can also be Events::

as a Button_Click_Event, or a
Key_Press_Event of a Textbox or
load event of a Form…

next assign a Delegate for event handlers =>
call the System.EventHandler delegate in the
[Windows Form Design generated code] “wiring”
first you must build-out each method then wire events to these methods with delegates…

Adverbs / Operation Conditions (All methods) ::
Block, Refund, Cancel a [Deposit]

Adjectives::
Clearing, Processing[Deposit]

2) Identify & Define all Exceptions::
Harvest all “But ifs & When it is” from the Client
i.e. a negative number in Accounting must be red
then::.
Model & Develop a Class.cs file for EVERY
rules based exception you’ll need to handle
and::.
identify which exemptions youll have to custom define

3) Identify & Define all Operations::
Harvest all “When Operations” from the Client
i.e. Display new deposit of money from my account

// Property to return the list of deposits
public ArrayList NewDeposits
{

get
{
return newDeposits;
}
}

then::.
Model & Develop a Class.cs file for EVERY
rules based Business Action you’ll need to process
this begins to “wrangle-in” all [No3 class object] actions
i.e. Depositing money into my account cannot be negative Dollars

4) Identify every UI Event::
you’ll probably have a button*_Click statement driving each [No3 class object]

i.e. objectify EVERY SQL Statement and design a stored procedure for each

5) Identify each UI Form:: for each button*_Event

6) Model all Conditionals::
Weigh every newly defined [No3 class object]
against
every [No2s class object]
for points of implementation and strategic interlinking
then::.
sculpt an if statement for each [No2 class object]
throw ALL new argument(s) for each [No3 class object]

Design namespacing and make any neccesary aiases…
i.e.
using Widgets = MyCompany.CompanyWidgets.WidgetModelForApplication;
is now::
Widgets.
7) Establish a Plan for Garbage Collection (GC)::
you should have a POA for each form.The .NET GC uses generations to help optimize the collection process and free up resources. Generation 0 contains recently created, frequently accessed objects. Generations 1 and 2, which hold larger and less frequently accessed objects, are not collected as often as Generation 0. The GC will sweep through Generation 0 rather often and free up resources there, but when doing the sweep of Generation 0 it ignores Generations 1 and 2. This means that any objects you have that are using large, expensive resources, such as file and operating system resources or network and database connections, could adversely impact your application’s performance by holding on to precious system resources longer than needed.

  • One way to improve performance is to consider your object designs and, if you have resources being held by large, infrequently used objects, take steps to release them sooner than later.
  • One way to do this is to implement a Dispose() method on all objects that consume expensive resources that may not be collected and freed as part of Generation 0.
  • heres a Great walk down “memory” lane

8) Optimizing CodeBehind ::
When you construct things remember you must
a ) declare new instance,
b ) assign attributes
c ) wire it for events and map it to what it affects
d ) add code in the nested method as needed to handle what you are wanting it to do.
performance speed in efficient code is EVERYTHING ! Sometimes I struggle for hours to earn another microsecond on a callback to a large datagrid…
It can make all the difference using a decimal than a double int.

  • The first thing you need to understand ­ and never forget ­ is that you won’t go very far if you try to work against the JIT compiler.
  • Carefully choose using per-method (JIT) vs method pre-compilation (NGEN) which could lead to a performance increase only when you want to reduce the startup time of your application.
  • You should consider whether you should use threading (no more than 1 at a time / multi-threading decreases performance) and only use it if it is truly required.
  • Once you know whether you actually need threads, the next decision is whether you should manage the threading or allow the .NET CLR to handle it. As with the JIT compiler, thread management under .NET is optimized rather well.
  • The key to achieving maximum performance with threading is to recycle threads. Threads are objects, and their instantiation is costly. This is clearly an area where understanding the science of threading and the art of performance is critical.
  • Throwing exceptions is another area that can lead to performance degradation. It is important that you consider the use of exceptions and how they affect your application. Please understand that I am not advocating that you do not use “Try…Catch” blocks in your code, but rather that you understand when exceptions are thrown and how they impact your code. Exceptions, by sheer nature, are expensive operations.
  • Use the .NET performance counters to see how many exceptions your application is throwing.
  • Also, be wary of integration with unmanaged code in which things like COM objects and System API calls can throw exceptions that can impact performance.
  • The ability to achieve better performance is often a result of how you balance the work to be performed by the client and the server.
  • You will dramatically increase performance if you can package the data you need to send across the wire while minimizing the number of method calls.
  • Go Native
    The use of native data types will help minimize the expense associated with marshaling. You incur expense, and thereby degrade performance, when you create situations where data translation is required. For instance, moving data from ASCII to Unicode ­ or in some cases from XML to another format ­ can create expensive marshaling scenarios. While planning your application you can drastically improve performance if your development team agrees on how you will manage data between your client and server objects.
  • Use the Right GC
    The .NET CLR has two garbage collectors, the workstation version (mscorwks.dll) and the server version (mscorsvr.dll). The server version is optimized for throughput and is also more aggressive about collections, so it minimizes memory fragmentation, takes advantage of multiple processors, and can also support multiple heaps. The workstation version minimizes latency and can also recognize multiple processors, but is best used in a single-processor workstation scenario. In some cases you may be running your client objects on a multiprocessor workstation communicating with objects on a server. In this case you can force the workstation to use the server version of the GC so that you can reap the benefits of the server version even though you are running on a workstation.
  • Security
    The last area we will examine is the impact security has on performance. I left it for last because I honestly feel that security is an area where you need to be very careful that your quest for speed doesn’t leave you exposed.
    Security affects performance; .NET security is optimized and has several techniques it uses to minimize impact on performance, but there are situations where a security check on a method will cause a walk of the stack. One thing to do is minimize the stack walk. Yes, .NET does this on its own by using declarative security instead of imperative. When PermitOnly, Deny, or Assert are declared, you can avoid the stack walk. Another option is to do as many of your security checks at link time instead of runtime, using “LinkDemand” to do code checks, as opposed to identity checks.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Note to other developers :
Please consider this loose and mailable to evolve with your feedback. I think it is an essential tool for problem solving and want to continue to refine for the benefit of all…

PHP CLI Tips

Tuesday, November 7th, 2006

by typing man php you can see a manual page

first start of with understanding what modules are already installed.
php -m

php -v will tell you whether php is CGI or CLI