Popular recipes tagged "meta:language=php"http://code.activestate.com/recipes/tags/meta:language=php/2015-06-26T04:30:14-07:00ActiveState Code RecipesPrint Directly from web application to POS/EPS thermal printer (PHP)
2014-09-01T14:55:56-07:00imam feriantohttp://code.activestate.com/recipes/users/633541/http://code.activestate.com/recipes/578925-print-directly-from-web-application-to-poseps-ther/
<p style="color: grey">
PHP
recipe 578925
by <a href="/recipes/users/633541/">imam ferianto</a>
(<a href="/recipes/tags/kasir/">kasir</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/over/">over</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/pos/">pos</a>, <a href="/recipes/tags/printer/">printer</a>, <a href="/recipes/tags/tiketing/">tiketing</a>).
Revision 2.
</p>
<p>this php script will printout barcode label directly from the web by phpscript</p>
print qrcode to usb termal RP80 printer from web base app (PHP)
2014-09-09T09:35:32-07:00imam feriantohttp://code.activestate.com/recipes/users/633541/http://code.activestate.com/recipes/578930-print-qrcode-to-usb-termal-rp80-printer-from-web-b/
<p style="color: grey">
PHP
recipe 578930
by <a href="/recipes/users/633541/">imam ferianto</a>
(<a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/printing/">printing</a>, <a href="/recipes/tags/qrcode/">qrcode</a>).
</p>
<p>this script will print qrcode from php script.
the printer is attached on webserver usb port,
see my other article here:
<a href="http://code.activestate.com/recipes/578925-print-directly-from-web-application-to-poseps-ther/" rel="nofollow">http://code.activestate.com/recipes/578925-print-directly-from-web-application-to-poseps-ther/</a></p>
<p>and python escpos references:
<a href="https://code.google.com/p/python-escpos/wiki/Usage" rel="nofollow">https://code.google.com/p/python-escpos/wiki/Usage</a></p>
Detect what browser your website is being accessed from using php (PHP)
2013-06-19T20:09:55-07:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578571-detect-what-browser-your-website-is-being-accessed/
<p style="color: grey">
PHP
recipe 578571
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/browser/">browser</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/server/">server</a>).
</p>
<p>This is a short hack on how to figure out what OS you site is being accessed from. This is useful if you want to redirect to different versions of your site through php. </p>
php backwards compatibility porting tips (PHP)
2013-02-10T00:40:26-08:00imam feriantohttp://code.activestate.com/recipes/users/633541/http://code.activestate.com/recipes/578452-php-backwards-compatibility-porting-tips/
<p style="color: grey">
PHP
recipe 578452
by <a href="/recipes/users/633541/">imam ferianto</a>
(<a href="/recipes/tags/backwards/">backwards</a>, <a href="/recipes/tags/compatibility/">compatibility</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/php4/">php4</a>, <a href="/recipes/tags/php5/">php5</a>).
</p>
<p>Hello again, on december 2012, I was porting my old php code (php4) to new php 5.4.3.
There are to many errors within code, especially for session, eregi, global variables and others.
This some pieces step for compatibility porting:</p>
<ol>
<li><p>add global variable definiton on some function that need outside variable
<code>
function getuser(){
global $loginid,$password;
}
</code></p></li>
<li><p>replace eregi(/find/,str) with preg_match(//,str)</p></li>
<li><p>add function exists for function that not exists in php5.4.3.
for example:
<code>
if(!function_exists("session_is_registered")){
function session_is_registered($var){
return isset($_SESSION[$var]);
}
}
if(!function_exists("session_register")){
function session_register($var){
$_SESSION[$var]=$_GLOBALS[$var];
}
}
</code></p></li>
</ol>
<p>Ok there is my tips, how about you? </p>
Benchmark (PHP)
2015-06-26T04:30:14-07:00Roger Mbiama Assogohttp://code.activestate.com/recipes/users/4178746/http://code.activestate.com/recipes/578235-benchmark/
<p style="color: grey">
PHP
recipe 578235
by <a href="/recipes/users/4178746/">Roger Mbiama Assogo</a>
(<a href="/recipes/tags/perl/">perl</a>, <a href="/recipes/tags/ppi/">ppi</a>, <a href="/recipes/tags/scripts/">scripts</a>, <a href="/recipes/tags/vim/">vim</a>).
Revision 6.
</p>
<p>perl [ -sTtuUWX ] [ -hv ] [ -V[:configvar] ] [ -cw ] [ -d[t][:debugger] ] [ -D[number/list] ] [ -pna ] [ -Fpattern ] [ -l[octal] ] [ -0[octal/hexadecimal] ] [ -Idir ] [ -m[-]module ] [ -M[-]'module...' ] [ -f ] [ -C [number/list] ] [ -S ] [ -x[dir] ] [ -i[extension] ] [ [-e|-E] 'command' ] [ -- ] [ programfile ] [ argument ] [stap -L 'kernel.trace("*")'|sort] [feature]...
BEGIN {
my $b__dir = (-d '/home/angosson/perl'?'/var/www/cgi-bin/perl':( getpwuid($>) )[7].'/perl');</p>
<pre class="prettyprint"><code>unshift @INC,$b__dir.'5/lib/perl5',$b__dir.'5/lib/perl5/x86_64-linux-thread-multi',map { $b__dir . $_ } @INC;
</code></pre>
<p>}
require LWP::UserAgent;</p>
<p>my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;</p>
Web based Query Browser (PHP)
2011-06-15T03:54:02-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/577753-web-based-query-browser/
<p style="color: grey">
PHP
recipe 577753
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/based/">based</a>, <a href="/recipes/tags/browser/">browser</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/query/">query</a>, <a href="/recipes/tags/web/">web</a>).
</p>
<p>Query browser works </p>
<p>add password to this part of the code if you require a password for mysql</p>
<p>Code =</p>
<p>// Connect to the database
$conn = mysql_connect('localhost', 'root' 'PASSWORD GOES HERE");</p>
YouTube-like primary key generation (PHP)
2011-02-24T21:43:55-08:00Slava Yansonhttp://code.activestate.com/recipes/users/4176967/http://code.activestate.com/recipes/577571-youtube-like-primary-key-generation/
<p style="color: grey">
PHP
recipe 577571
by <a href="/recipes/users/4176967/">Slava Yanson</a>
(<a href="/recipes/tags/activerecord/">activerecord</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/unique/">unique</a>).
Revision 4.
</p>
<p>If you have more then 1 primary database servers - you have probably experienced the pain of primary key overlapping... Here is a super simple solution that will generate a hash of random letters and numbers.</p>
<p>Included is a sample ActiveRecord class (MyTable.php).</p>
PHP 'Struct' port (PHP)
2010-03-28T01:22:31-07:00Jeff Griffithshttp://code.activestate.com/recipes/users/835605/http://code.activestate.com/recipes/577160-php-struct-port/
<p style="color: grey">
PHP
recipe 577160
by <a href="/recipes/users/835605/">Jeff Griffiths</a>
(<a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/oop/">oop</a>).
Revision 2.
</p>
<p>In Ruby, the <a href="http://ruby-doc.org/core/classes/Struct.html">Struct class</a> is a convenient way to create a hash-like object on the fly and use it for your nefarious purposes. PHP 5+ can be convinced to do this type of things as well, it just doesn't have it out of the box. Here is a simple class that implements iterator and allows you to populate the internal data structure similar to how Ruby's Struct works. Syntactic sugar? Probably.</p>
<p>Note: I haven't bothered to implement the Ruby Struct API per se, Instead I just got something similar by implementing the Iterator interface and keeping things very PHP-like.</p>
Validating Emails (PHP)
2011-06-13T15:10:47-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/577198-validating-emails/
<p style="color: grey">
PHP
recipe 577198
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/emails/">emails</a>, <a href="/recipes/tags/validating/">validating</a>).
Revision 2.
</p>
<p>a small script that can be used for Validating Emails on </p>
<ul>
<li>Login pages</li>
<li>forums </li>
</ul>
<p>changed to preg_match from eregi function. now scripted validates everything typed in input boxes </p>
<p>Old Code = </p>
<pre class="prettyprint"><code> foreach($Email as $Emails)
{ // checks Emails - .net , .com , .au & etc
if(eregi("[a-zA-Z0-9]@+[a-z].{1,}com$",trim($Emails))|| eregi(
"[a-zA-Z0-9]@+[a-z].{1,}net$",trim($Emails)))
</code></pre>
<p>New Code = </p>
<pre class="prettyprint"><code> foreach($Email as $Emails)
{ // checks Emails - .net , .com , .au & etc
if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z]
[0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $Emails))
</code></pre>
<p>i changed from eregi function to preg_match function because eregi was taking out of PHP version 5.3.0 and 5.3.5.</p>
Generate an alpha-numeric password salt (PHP)
2010-02-25T14:07:08-08:00Jayesh Shethhttp://code.activestate.com/recipes/users/4173165/http://code.activestate.com/recipes/577071-generate-an-alpha-numeric-password-salt/
<p style="color: grey">
PHP
recipe 577071
by <a href="/recipes/users/4173165/">Jayesh Sheth</a>
(<a href="/recipes/tags/md5/">md5</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/random_number/">random_number</a>, <a href="/recipes/tags/salt/">salt</a>).
</p>
<p>Generate an alpha-numeric password salt (with a default of 32 characters)</p>
Generate a salt (PHP)
2012-07-10T19:52:17-07:00Xavier L.http://code.activestate.com/recipes/users/4171602/http://code.activestate.com/recipes/576894-generate-a-salt/
<p style="color: grey">
PHP
recipe 576894
by <a href="/recipes/users/4171602/">Xavier L.</a>
(<a href="/recipes/tags/crypt/">crypt</a>, <a href="/recipes/tags/generation/">generation</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/pass/">pass</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/salt/">salt</a>, <a href="/recipes/tags/secure/">secure</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/string/">string</a>).
Revision 6.
</p>
<p>This function will generate a salt for use with passwords ranging using characters in range a to z, A to Z, 0 to 9 and !@#$%&<em>?. The characters are sorted in a random value and can appear more than one time in the string. This way, this function is more powerful than the *shuffle()</em> function. This means that the salt could also be longer than the character list.</p>
Hash text simply (PHP)
2012-04-30T21:43:00-07:00Xavier L.http://code.activestate.com/recipes/users/4171602/http://code.activestate.com/recipes/576893-hash-text-simply/
<p style="color: grey">
PHP
recipe 576893
by <a href="/recipes/users/4171602/">Xavier L.</a>
(<a href="/recipes/tags/crypt/">crypt</a>, <a href="/recipes/tags/extensible/">extensible</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/secure/">secure</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/simple/">simple</a>).
Revision 5.
</p>
<p>This is a simply and extensible script that can be used to rapidly has any amount of text using PHP's hash() built-in function.</p>
<p>It recognizes when the page is loaded for the first time and displays a form with options. Afterward, it display the selected hash(es), with a link at the bottom to start again.</p>
PHP Login page (PHP)
2010-04-17T13:31:03-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/576680-php-login-page/
<p style="color: grey">
PHP
recipe 576680
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/login/">login</a>, <a href="/recipes/tags/page/">page</a>).
Revision 2.
</p>
<p>this is a small php login script.</p>
PHP - Background Colour Changer (PHP)
2009-03-05T05:22:31-08:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/576679-php-background-colour-changer/
<p style="color: grey">
PHP
recipe 576679
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/background/">background</a>, <a href="/recipes/tags/changer/">changer</a>, <a href="/recipes/tags/colour/">colour</a>).
Revision 2.
</p>
<p>this is a script that changes the colour of the background to the day of the week, the code uses if and elseif...</p>
a more reliable DOCUMENT_ROOT (PHP)
2008-12-25T18:55:33-08:00Gui Rhttp://code.activestate.com/recipes/users/4166241/http://code.activestate.com/recipes/576595-a-more-reliable-document_root/
<p style="color: grey">
PHP
recipe 576595
by <a href="/recipes/users/4166241/">Gui R</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>$_SERVER['DOCUMENT_ROOT'] has been known to be broken on some servers.
This is a bit of logic to retrieve the document root more reliably.</p>
Youtube Downloader (PHP)
2008-12-03T17:37:28-08:00yeni setiawanhttp://code.activestate.com/recipes/users/4168289/http://code.activestate.com/recipes/576579-youtube-downloader/
<p style="color: grey">
PHP
recipe 576579
by <a href="/recipes/users/4168289/">yeni setiawan</a>
(<a href="/recipes/tags/download/">download</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/youtube/">youtube</a>, <a href="/recipes/tags/youtube_downloader/">youtube_downloader</a>).
</p>
<p>This is a series of function that you can use to download video(s) from <a href="http://Youtube.com" rel="nofollow">Youtube.com</a></p>
Implementation of a single linked list in PHP (PHP)
2008-09-11T12:44:41-07:00sameer boratehttp://code.activestate.com/recipes/users/4167072/http://code.activestate.com/recipes/576498-implementation-of-a-single-linked-list-in-php/
<p style="color: grey">
PHP
recipe 576498
by <a href="/recipes/users/4167072/">sameer borate</a>
(<a href="/recipes/tags/linked_list/">linked_list</a>, <a href="/recipes/tags/php/">php</a>).
</p>
<p>Implementation of a single linked list in PHP with Unit Test</p>
Converting MySQL queries to XML (PHP)
2008-09-11T13:16:40-07:00sameer boratehttp://code.activestate.com/recipes/users/4167072/http://code.activestate.com/recipes/576499-converting-mysql-queries-to-xml/
<p style="color: grey">
PHP
recipe 576499
by <a href="/recipes/users/4167072/">sameer borate</a>
(<a href="/recipes/tags/mysql/">mysql</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/xml/">xml</a>).
</p>
<p>Converting MySQL queries to XML</p>
SPICE for PHP (PHP)
2008-04-30T17:30:49-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/572178-spice-for-php/
<p style="color: grey">
PHP
recipe 572178
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/security/">security</a>).
</p>
<p>SPICE has been in development since 2002. The first version was implemented
on a graphing calculator, designed to work with base 27 numbers, and used hard
coded keys. The program was ported to Java and later redesigned in Python. This
implementation was ported directly from the standard code base.</p>
Bass class for PDO abstraction (PHP)
2010-03-28T01:16:30-07:00Jeff Griffithshttp://code.activestate.com/recipes/users/835605/http://code.activestate.com/recipes/522993-bass-class-for-pdo-abstraction/
<p style="color: grey">
PHP
recipe 522993
by <a href="/recipes/users/835605/">Jeff Griffiths</a>
(<a href="/recipes/tags/database/">database</a>).
Revision 2.
</p>
<p>This is a simple base class that extends PDO and provides some useful helper functions such as _getRows and _getAsRow()</p>