PHP

Print star pattern in PHP

Pattern 1

Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Pattern 2

Output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Pattern 3

Output
*
* *
* * *
* * * *
* * * * *

Pattern 4

 

Output
*
* *
* * *
* * * *
* * * * *

Secondary site setting :

SET UP A New Site(John project)

1) Create domain id for the site.

steps to Create a new domain:

1. create a new domain in appolo – http://stageadmin.1degreeworld.biz/domain/index (if its a secondary site means give domain group as secondary site).
2. Create a GAPI keys for the created domain – http://stageadmin.1degreeworld.biz/gapi/manage_keys
3. Map new domain with GAPI and other API’s – http://stageadmin.1degreeworld.biz/api_mapping
4. Edit the “Set Domain Credentials” icon from the domain api list for the new domain.
Keys can be get from the Step2 and add the GAPI urls for live, stage and dev.
5.Map the other apis used for the site using domain api mapping http://stageadmin.1degreeworld.biz/api_mapping

email setup:
need to configure emails in following tables.
domain_email_settings
domain_email_access
domain_email_accounts
note: this is not need for secondarysites coz mail send via tourbeaver.

2) create a secondary site.

there are 3 checkouts available in SecondarySites,
1. austin checkout
2. alcatrazticket checkout
3. devdbtesttemp checkout

1 create the website using tb_websites menu in venus. this is saved in tb_websites.

note: city name and state code should be mapped with tb_priceline_city table.

2. get the website id in tb_website and manually add the tb_website_id in domain table .

Reduce site loading time – mod_deflate :

Add the below code to .htaccess file to compress the output of the site then the site performance will be better.

<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>


Setting default permissions for newly created files and sub-directories in Linux :

chmod g+s <directory>  //set gid 
setfacl -d -m g::rwx /<directory>  //set group to rwx default 
setfacl -d -m o::rx /<directory>   //set other

Next we can verify:

getfacl /<directory>

Output:

# file: ../<directory>/
# owner: <user>
# group: media
# flags: -s-
user::rwx
group::rwx
other::r-x
default:user::rwx
default:group::rwx
default:other::r-x
Difference between php4 and php5 PHP5 introduces many new features, I have mentioned some of them:Unified Constructors and Destructors:
In PHP4, constructors had same name as the class name where In PHP5, you simply need to name your constructors as __construct()
Abstract:
In PHP5 you can declare a class as Abstract.Startic Methods and properties:
Static methods and properties are also available. When you declare a class member as static, then you can access members using :: operator without  creating an instance of class.


_autoload()
PHP5 introduces a special function called __autoload()Final:
PHP5 allows you to declare a class or method as Final Magic Methods
PHP5 introduces a number of magic methods.
__call, __get, __set and __toString————————————————————————————————————————————————————–

PHP Server variables :

PHP : $_SERVER[‘PHP_SELF’]

PHP : $_SERVER[‘argv’]

PHP : Super global variable: $argc

PHP : $_SERVER[‘GATEWAY_INTERFACE’]

PHP : $_SERVER[‘SERVER_ADDR’]

PHP : $_SERVER[‘SERVER_NAME’]

PHP : $_SERVER[‘SERVER_SOFTWARE’]

PHP : $_SERVER[‘SERVER_PROTOCOL’]

PHP : $_SERVER[‘REQUEST_METHOD’]

PHP : $_SERVER[‘REQUEST_TIME’]

PHP : $_SERVER[‘QUERY_STRING’]

PHP : $_SERVER[‘HTTP_ACCEPT’]

PHP : $_SERVER[‘HTTP_ACCEPT_CHARSET’]

PHP : $_SERVER[‘HTTP_HOST’]

PHP : $_SERVER[‘HTTP_USER_AGENT’];

PHP : $_SERVER[‘REMOTE_PORT’]

PHP : $_SERVER[‘SCRIPT_FILENAME’]

PHP : $_SERVER[‘SERVER_ADMIN’]

PHP : $_SERVER[‘SERVER_PORT’]

PHP : $_SERVER[‘SERVER_SIGNATURE’]

PHP : $_SERVER[‘PATH_TRANSLATED’]

PHP : $_SERVER[‘SCRIPT_NAME’]

PHP : $_SERVER[‘SCRIPT_URI’]

– See more at: http://www.w3resource.com/php/super-variables/$_SERVER.php#sthash.hKXsezPK.dpuf

————————————————————–

To change the date format :

$payment_date = date(‘Y-m-d H:i:s’,strtotime($_POST[‘payment_date’]));
Dubai Time Zone :
Example : 1
<?php
date_default_timezone_set(‘Asia/Dubai’);
print date(“F d, Y H:i:s”, time())
?>
Example : 2
$timezone = “Asia/Dubai”;
if(function_exists(‘date_default_timezone_set’)) date_default_timezone_set($timezone);
—————————————-
Live server configuration :
This program makes use of the Zend Scripting Language Engine:
  • Linux Server (Apache)
  • PHP Version 5.2.17
  • Mysql Version 5.5.23
  • PHPmyadmin version 3.4.11.1
  • Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
  • With the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd., and
  • With Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
  • IonCube Loader Enabled
  • GD Library needs to be installed
  • option to edit php.ini file
  • mod_rewrite Enabled
  • mime_magic.debug – OFF
  • Session Support – Enabled

Java script Validation :

function team_regform()
{
var Errmsg = true;

if(document.getElementById(“logo”).value == “”)
{
document.getElementById(“err_logo”).style.display = “block”;
document.getElementById(“err_logo”).innerHTML = “Logo field is required”;
document.getElementById(“logo”).focus();
Errmsg = false;
}

if(document.getElementById(“logo”).value != “”)
{
var fup = document.getElementById(‘logo’);
var fileName = fup.value;
var ext = fileName.substring(fileName.lastIndexOf(‘.’) + 1);
if(ext == “gif” || ext == “GIF” || ext == “JPEG” || ext == “jpeg” || ext == “jpg” || ext == “JPG” || ext == “png”)
{
Errmsg = true;
}
else
{
document.getElementById(“err_logo”).innerHTML = “Invalid logo format”;
document.getElementById(“logo”).focus();
Errmsg = false;
}
}

 

var checkString = document.getElementById(“phone”).value;
if (checkString != “”)
{
if(!checkString.match(/^[0-9\+\-\(\)]/))
{
document.getElementById(“err_phone”).style.display = “block”;
document.getElementById(‘err_phone’).innerHTML = “Please enter valid contact number”;
document.getElementById(‘phone’).focus();
Errmsg = false;
}
}

 

if(document.getElementById(’email’).value != “”)
{

var email_id = document.getElementById(’email’);
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email_id.value))
{
document.getElementById(“err_email”).style.display = “block”;
document.getElementById(‘err_email’).innerHTML = “Please enter valid email”;
document.getElementById(’email’).focus();
Errmsg = false;
}
}

 

if(Errmsg == false)
{
return false;
}
else
{
return true;
}
}

function empty(id)
{
document.getElementById(id).innerHTML = “”;
return true;
}

———————————————————————————————-

SEO Friendly URL : (Linscan/.htaccess)

Options +FollowSymLinks
RewriteEngine on
RewriteRule index-(.*)-(.*)\.html$ index.php?id=$1&lang=$2
RewriteRule index-(.*)\.html$ index.php?logo=$1
RewriteRule career-(.*)-(.*)\.html$ career.php?id=$1&lang=$2
RewriteRule sitemap-(.*)-(.*)\.html$ sitemap.php?id=$1&lang=$2
RewriteRule sitemap-(.*)\.html$ sitemap.php?id=$1
RewriteRule enquiry-(.*).html$ enquiry.php?id=$1
RewriteRule feedback-(.*)\.html$ feedback.php?id=$1
RewriteRule vision-mission-(.*)-id-(.*)\.html$ vision_mission.php?sno=$1&id=$2
RewriteRule aboutus-(.*)\.html$ who_we_are.php?id=$1
RewriteRule location-map-(.*)\.html$ location_map.php?id=$1
RewriteRule disclaimer-(.*)\.html$ disclaimer.php?id=$1
RewriteRule privacy-policy-(.*)\.html$ privacy_policy.php?id=$1
RewriteRule help-(.*)\.html$ help.php?id=$1
RewriteRule contest-(.*)\.html$ contest_form.php?id=$1
RewriteRule search-(.*)\.html$ search.php?lang=$1
RewriteRule result-(.*)-(.*)\.html$ search_result.php?id=$1&lang=$2
RewriteRule location-map-(.*)\.html$ location_map.php?id=$1
RewriteRule vision-mission-(.*)-(.*)\.html$ vision_mission.php?sno=$1&id=$2
RewriteRule news-press-release-(.*)-(.*)\.html$ news_press_release.php?sid=$1&id=$2
RewriteRule news-press-viewall-(.*)\.html$ news_press_viewall.php?id=$1
RewriteRule (.*)-(.*)-(.*)\.html$ submenu.php?name=$1&id=$2&lang=$3


Virtual Host Creation :

virtual host for each project in our local and set a separate environment for that virtual host, so that it doesn’t have to conflict with the localhost environment which John (and the team at his end) may also be using.

For example, for devehappy, see the main index.php, I have set up a separate environment “vivid_local” for the (virtual) host “devehappy.vivid” .
So the config folder for this environment is config/vivid_local

So here are the steps to set up a virtual host in your local;

1) In C:\Windows\System32\drivers\etc\hosts file
add this
127.0.0.1 localhost (Don’t add this line if it already exists)
127.0.0.1 devehappy.vivid

2) In your xampp\apache\conf\extra\httpd-vhosts.conf  file (for wamp this path may be a little different)
add this
NameVirtualHost *:80 (Don’t add this line if it already exists)
<VirtualHost *:80>
DocumentRoot “D:/xampp/htdocs/devehappy”
ServerName devehappy.vivid
</VirtualHost>

3) Restart apache

Now you should be able to access the site with http://devehappy.vivid


What will the different functions return?

All of the mentioned functions will return an array, the differences between them is what values that are being used as keys in the returned object.

  • mysql_fetch_rowThis function will return a row where the values will come in the order as they are defined in the SQL query, and the keys will span from 0 to one less than the number of columns selected.
  • mysql_fetch_assocThis function will return a row as an associative array where the column names will be the keys storing corresponding value.
  • mysql_fetch_arrayThis function will actually return an array with both the contents of mysql_fetch_rowand mysql_fetch_assoc merged into one. It will both have numeric and string keys which will let you access your data in whatever way you’d find easiest.It is recommended to use either _assoc or _row though.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s