+ Almost all quality improvement comes via simplification of design, manufacturing... layout, processes, and procedures.

July 30, 2010, 4:52 pm

Redirect mobile users to a mobile friendly page with php

June 25, 2009

After allot of trial and error I ended up coming up with some code that will redirect users to a mobile friendly page, this method won’t really be useful in about 5 years because modern browsers like safari allow full page viewing but this will get you by until then. Remember this code will have to change constantly if you want to stay up to date with the latest hand held devices and mime types.

To get started all you have to do is place the following code in the stop of your php page. If your loading an application you can post this below your application just don’t output any data before the code is executed.


$mobile_browser = '0';if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',
strtolower($_SERVER['HTTP_USER_AGENT']))){
$mobile_browser++;
}

if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or
((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
$mobile_browser++;
}

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda','xda-');

if(in_array($mobile_ua,$mobile_agents)){
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
$mobile_browser=0;
}

//change this to your mobile friendly page
if($mobile_browser>0){
header( "Location: http://www.yourwebsite.com/mobile/" ) ;
} else {
// do something else
}

$ua = $HTTP_USER_AGENT;
if (stristr($ua, "Windows CE") or stristr($ua, "AvantGo") or stristr($ua,
"Mazingo") or stristr($ua, "Mobile") or stristr($ua, "T68") or stristr($ua,
"Syncalot") or stristr($ua, "Blazer") or stristr($ua, "NetFront"))
{
$DEVICE_TYPE="MOBILE";
}

if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE")
{
//change this to your mobile friendly page
header( "Location: http://www.yourwebsite.com/mobile/" ) ;
exit;
}

?>

Posted by Anthony under PHP | Comments (2)

Online food ordering script “Restaurant Biller” released with pricing!

March 8, 2009

rest.png

  • Easy AJAX powered checkout system
  • Receive the orders directly through email within 30 seconds of placed order
  • Easy customization for those who want to modify their site
  • Set the hours you would like your store open
  • Turn your store off and on through the administration panel
  • Enable Credit or disable credit cards
  • Enable or disable delivery and delivery fees
  • Modify your home page directly from a control panel
  • Add Edit and delete categories to your menu
  • Add Edit and delete menu items with extented features
  • Each site has a contact us page for customer questions
  • Edit the hours you would like your online store open
  • Add an addition cost for delivery, tax prices or order processing fees
  • Built In newsletter system
  • Free updates

Click here for a demo

Posted by Anthony under AJAX, Online Food Ordering, PHP, Web Technology, mysql | Comments (0)

PHP Function: Make non linked links clickable

December 16, 2008

Recently I came across a problem making a twitter plugin. I needed to make links which had no “a” tag into links. You can do this progamaticly and here is the solution:

If you are going to use this script please download from here: links.php.txt

Code (php)
  1. function makeClickableLinks($text) {
  2.  
  3. $text = eregi_replace(’(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)’,
  4.  
  5.     ’<a href="1">1</a>’, $text);
  6.  
  7.   $text = eregi_replace(’([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)’,
  8.  
  9.     ’1<a href="http://2">2</a>’, $text);
  10.  
  11.   $text = eregi_replace(’([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})’,
  12.  
  13.     ’<a href="mailto:1">1</a>’, $text);
  14.  
  15. return $text;
  16.  
  17. }
  18.  
  19. // Usage
  20.  
  21. // Email address example
  22.  
  23. $text = "you@example.com";
  24.  
  25. echo makeClickableLinks($text);
  26.  
  27. echo "
  28.  
  29. ";
  30.  
  31. // URL example
  32.  
  33. $text = "http://www.example.com";
  34.  
  35. echo makeClickableLinks($text);
  36.  
  37. echo "
  38.  
  39. ";
  40.  
  41. // FTP URL example
  42.  
  43. $text = "ftp://ftp.example.com";
  44.  
  45. echo makeClickableLinks($text);

Posted by Anthony under PHP | Comments (0)

Cubecart product compare mod

December 15, 2008

Cubecart product compare mod allows customers to compare 2 or more products, the customer can see the price,description, image, name and weight. The Cubecart product compare mod also makes it simple to add new fields to the compare mod. For instance if you own a computer shop you can add some custom fields to the inventory table and compare those items on the compare page by just drawing the variable. With a simple installation this mod is a sure win for your cubecart installation.

Price: $15
License: unlimited domain
Demo: http://worcesterwideweb.com/store/index.php?act=viewCat&catId=1

compare.jpg


Posted by Anthony under Cubecart, News, PHP | Comments (3)

Restaurant Online Ordering System Beta available!

December 7, 2008

The Restaurant Biller application is now available! With the features  listed below and the low price it costs to use this application its a sure hit for small business restaurants world wide. Here are the features the Restaurant Biller boasts:

The online restaurant ordering system for small to large businesses. More and more people are going online to search for food in their area rather then using the yellow pages. Restaurant Biller© created an online solution for those restaurants to have an online menu where customers can place orders. This application is very powerful and easy to use with features allowing you to easily control every aspect of your website. Listed below are some of the features included in this application.

  • Easy AJAX powered checkout system
  • Receive the orders directly through email within 30 seconds of placed order
  • Easy customization for those who want to modify their site
  • Modify your home page directly from a control panel
  • Add Edit and delete categories to your menu
  • Add Edit and delete menu items with extented features
  • Each site has a contact us page for customer questions
  • Edit the hours you would like your online store open
  • Add an addition cost for delivery, tax prices or order processing fees
  • Free updates

Click here to view the demo and website
or
Click here to enquire about getting setup on this system

Posted by Anthony under News, Online Food Ordering, PHP, Portfolio, Web Technology | Comments (0)

php 5 and imagecreatefromjpeg() recoverable error: Premature end of JPEG file

March 17, 2008

Ok I recently came up with a problem creating thumbnails for a project I am working on. I was stumped for hours, it seems that some files that were saved from a mac or certain photo editing programs would cause php to not recognize it a jpg thus giving the error:  

imagecreatefromjpeg() : gd-jpeg, libjpeg: recoverable error: Premature end of JPEG

After researching this problem I realized it was a problem with php 5 and gd2. Heres how to fix it

  • php 4 : No action neccesarry it should work fine
  • php 5.0 – 5.1.2 = Upgrade to the latest php 5
  • php 5.1.3 – current = Declare this variable in your file before calling imagecreatefromjpeg()   

ini_set(’gd.jpeg_ignore_warning’, 1);

Doing that will cause gd2,php to ignore the error and continue where it use to just fail and do nothing.

Posted by Anthony under PHP | Comments (13)

Cubecart custom category order

August 5, 2007

So I developed another new mod for cubecart, this one allows you to sort out your categories in cubecart the way you want without staying with the normal sort by name or id as seen in other mods. This mod only modifies 3 files and installs one column “pos” to your database to do the ordering. Remember to back up your database and files before attempting any modification on your original files. To download this file click on the link below.

Custom category ordering 1.0

custom_category_order_1.3 (updated for manual ordering)

Posted by Anthony under Cubecart, PHP | Comments (11)

Cubecart multiple delete and re categorize admin hack

July 15, 2007

I am developing a new shopping cart using the cubecart system, the client has about 2500 parts in the database. After importing these products into the database I noticed that a good 500 were mis categorized and about 100 were out of date and had to be removed. Cubecart didnt have any support for multi re-categorize or multiple deletes so I created the following hack. This hack will allow you to check off all the products on the product view page and do 2 different things. Either delete the selected products or move the selected products to a different category. To enable this hack in your cubecart admin panel paste the code in the following areas .

Due to people not being able to copy the code correctly I have pasted it in a text file which can be viewed here
install_multi_delete_recat.txt

You can also download my own index.php with the mod already installed, this will work perfect for you if you havent already modded your admin/products/index.php. Download that file here: install_multi_delete_recat-2.zip

Posted by Anthony under Cubecart, PHP, mysql | Comments (2)

mysql update from another table

July 3, 2007

Recently I needed to update a bunch of rows in mysql with information from another table. I will explain how to do this simple process.

  1. Open up phpmyadmin or similar database editor
  2. view the sql query below
Code (sql)
  1.  
  2. UPDATE updatefrom p, updateto pp
  3. SET pp.last_name = p.last_name
  4. WHERE pp.visid = p.id

Lets say we have 2 tables one named main and one named updateto and one named updatefrom, In the first line we assign variables to these t tables (p and pp) from there we can call column names using this format table.columname. If we had first_name and last_name in both tables and wanted to update the “updateto” table with the info from “updatefrom” this is how you would write it.

Posted by Anthony under PHP, Web Technology, mysql | Comments (4)

Dynamic PHP Email Forms without massive amounts of code

May 19, 2007

Ever had a HUGE form that just emails basic information and just thought to yourself, damn there has to be an easier way to do this! I’ve got a solution that will work, basicly what it does is takes the form loops all the input fields and sends them through email (or proccess them any way you would like) I’ll go over the basics here.

First we need a form Lets start with something simple

Code (html)
  1. <form action="process.php" method="post">
  2. Name:     
  3. <input name="Name" />
  4. Email:     
  5. <input name="Email" />
  6. Address:     
  7. <input name="Address" />
  8. <input name="Address" type="submit" />
  9. </form>

Now to process it, first we will import all variables and send them through a loop

Code (php)
  1.  
  2.  
  3. @import_request_variables("gpc");     
  4.  
  5. $server = $_SERVER['HTTP_HOST'];     
  6.  
  7. foreach($_POST as $key => $data) {
  8.   if($key != ‘required’) {
  9.       if($data !=”) {
  10.           $message .= ‘<strong>’.$key.’</strong>: ‘.$data.”;
  11.       }
  12.   }
  13. }

Now you can display your information if you wish or go further to send it with an email, im using a email class i built which you can download here.

Code (php)
  1.  
  2.  
  3. echo ‘
  4. <p style="background-color: #f2fced; margin: 20px; border: #cccccc 1px solid; padding: 20px"> </p>
  5.  
  6. <h4>Your forum Has been sucessfully sent with the following information</h4>
  7. ‘.$message.’   
  8.  
  9. ‘;     
  10.  
  11. $m = new Mail(); // create the mail
  12. $m->From( "email@server.com" );
  13. $m->To( "email@server.com"  );
  14. $m->Subject( ‘New forum submission from  ‘.$server.’ Contact Page’ );
  15. $m->Body( $message);
  16. $m->Priority(4);     
  17.  
  18. $m->Send(); // send the mail

This method is very easy for sending simple forms where serverside validation is not needed. Check it out play with it and post if you have any questions ill be happy to help!

Posted by Anthony under PHP | Comments (2)