You can use XML language to transfer large data from one domain to other. Suppose domain-x wants to send data from its database to domain-y. Then domain-x will generate xml file for the database and send it to the domain-y via post method for security purpose. Upon receipt of xml file from domain-x, the domain-y will store that xml file in one folder and create one new row in received_xml table, and call a xmlparser script through cron job to extract information from the xml files and store in database and then move that parsed xml file to some other folder(named like parsed) and remove the record from receive_xml table.
For parsing there are so many free scripts available in php,ruby etc., xmltoarray is one of the technique.
Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
Wednesday, August 11, 2010
Thursday, August 5, 2010
URL push and URL pull to send / retrieve information between cross domains
Hello friend,
Today I have done a small but very useful functionality i.e URL push and URL pull means you can send information to remote url and retieve information from other url. Getting information is easy and i think all developers know it, but sending information is little tricky when we don't know how the post variable names.
Below is the code to track the post parameter names and values in targetsite.
//extract($_POST);
foreach($_POST as $key=>$value)
{
echo $key.'='.$value.'
';
}
echo $_SERVER['HTTP_REFERER'];
/*Output:
key = value
key = value
etc..,
http://from-site-name.com/filename
*/
?>
So here in foreach loop you will get the post param names and values. So you can store in db with table structure as id autoincrement, key, value, referrer,posted_on. OR use xml file to store the information in structured way likevaluevalueetc..,
Ex: http://formsite-name.com/postinfo.php
##################################################################
form action="http://targetsite.com/getvalues.php" method="post"
Name:input type="text" name="name"
Address:input type="text" name="address"
Email:input type="text" name="email"
input type="submit" value="Submit"
/form
#####################################################################
When user submits the above form the remote script (i.e mentioned in form action will execute) here it is at http://targetsite.com/getvalues.php
//extract($_POST);
foreach($_POST as $key=>$value)
{
echo $key.'='.$value.'
';
}
echo $_SERVER['HTTP_REFERER'];
/*Output:
name = postedname
address = postedaddress
email = postedemail
http://formsite-name.com/postinfo.php
*/
?>
Today I have done a small but very useful functionality i.e URL push and URL pull means you can send information to remote url and retieve information from other url. Getting information is easy and i think all developers know it, but sending information is little tricky when we don't know how the post variable names.
Below is the code to track the post parameter names and values in targetsite.
//extract($_POST);
foreach($_POST as $key=>$value)
{
echo $key.'='.$value.'
';
}
echo $_SERVER['HTTP_REFERER'];
/*Output:
key = value
key = value
etc..,
http://from-site-name.com/filename
*/
?>
So here in foreach loop you will get the post param names and values. So you can store in db with table structure as id autoincrement, key, value, referrer,posted_on. OR use xml file to store the information in structured way like
Ex: http://formsite-name.com/postinfo.php
##################################################################
form action="http://targetsite.com/getvalues.php" method="post"
Name:input type="text" name="name"
Address:input type="text" name="address"
Email:input type="text" name="email"
input type="submit" value="Submit"
/form
#####################################################################
When user submits the above form the remote script (i.e mentioned in form action will execute) here it is at http://targetsite.com/getvalues.php
//extract($_POST);
foreach($_POST as $key=>$value)
{
echo $key.'='.$value.'
';
}
echo $_SERVER['HTTP_REFERER'];
/*Output:
name = postedname
address = postedaddress
email = postedemail
http://formsite-name.com/postinfo.php
*/
?>
Tuesday, August 3, 2010
Don't do more work than you have to - Use auto deploy tools
Hello,
Human beings can't remember everything but machines can. Everyday you work on a project and changed many files and altered database tables but forgot some things to update in live server while depoloying code. Use some third party tools to deploy your php applications without missing small change or db updates. There are many such tools available, capistrano is one of the famous tool for automate the deployment process. Many people think it is only for RoR applications deployment but it is for all. You can find more info for how to auto deploy php applications with capistrano from here http://www.jonmaddox.com/2006/08/16/automated-php-deployment-with-capistrano/#comment-10668
Human beings can't remember everything but machines can. Everyday you work on a project and changed many files and altered database tables but forgot some things to update in live server while depoloying code. Use some third party tools to deploy your php applications without missing small change or db updates. There are many such tools available, capistrano is one of the famous tool for automate the deployment process. Many people think it is only for RoR applications deployment but it is for all. You can find more info for how to auto deploy php applications with capistrano from here http://www.jonmaddox.com/2006/08/16/automated-php-deployment-with-capistrano/#comment-10668
Friday, July 30, 2010
Auto update Database from one server to another or developement database to live database
The below shell script will take the database backup and uploaded to the svn server. Call this script through cron job so that it will auto execute and send the dbbackup to the svn repo where ever you want. From svn you should auto deploy code to the sever, so run the cron tab in the target server and execute a script which empty the current database and update with this new one. Mostly usefull in while working with drupal, In drupal many things are stored in database instead of files, so that while you developing application, database also updated daily for each module addtion and upgradation etc., So developement database and live database are varies frequently. You can update the files easily using svn but can't update db because we don't know the every change in db while working. In this situation use the below shell script it will update the live database with your development database.
#!/bin/bash
#
# Configuration
#
# Database connection information
dbname="db_name"
dbhost="localhost" # leave as is unless have specific reason to change
dbuser="db_user"
dbpw="db_pass"
# Dump associated information
dump_directory="/path/to/sql/directory" # path to dump dir NO FILE NAME, note end slash
dump_name="dumpname.sql"
logfile=$dump_directory"dumpandcommitt.txt" # name of log file to use
#
# dump db and log on screen and in log file
#
cd $dump_directory
mysqldump --user=$dbuser --password=$dbpw --add-drop-table $dbname > $dump_name
echo " Dumped drupal database, using user:$dbuser; database:$dbname host:$dbhost"
echo " Dumped drupal database, using user:$dbuser; database:$dbname host:$dbhost" >> $logfile
#
# commit the newly dumped db - note you'll need to svn add to repository first before this will work
#
svn commit -m "auto committed db"
echo " Committed new db"
echo " Committed new db" >> $logfile
endtime=`date`
echo "Backup completed $endtime" >> $logfile
Save the above script as db_import_upload.sh
In terminal call as
$ ./db_import_upload.sh
#!/bin/bash
#
# Configuration
#
# Database connection information
dbname="db_name"
dbhost="localhost" # leave as is unless have specific reason to change
dbuser="db_user"
dbpw="db_pass"
# Dump associated information
dump_directory="/path/to/sql/directory" # path to dump dir NO FILE NAME, note end slash
dump_name="dumpname.sql"
logfile=$dump_directory"dumpandcommitt.txt" # name of log file to use
#
# dump db and log on screen and in log file
#
cd $dump_directory
mysqldump --user=$dbuser --password=$dbpw --add-drop-table $dbname > $dump_name
echo " Dumped drupal database, using user:$dbuser; database:$dbname host:$dbhost"
echo " Dumped drupal database, using user:$dbuser; database:$dbname host:$dbhost" >> $logfile
#
# commit the newly dumped db - note you'll need to svn add to repository first before this will work
#
svn commit -m "auto committed db"
echo " Committed new db"
echo " Committed new db" >> $logfile
endtime=`date`
echo "Backup completed $endtime" >> $logfile
Save the above script as db_import_upload.sh
In terminal call as
$ ./db_import_upload.sh
About Foxycart
Foxycart is a third party service which offer ecommerce solution for your products by just creating account in foxycart and small configurations. After that we should integrate simple form in our own application and submit product details to the foxycart. Then it will take care of the checkout and payment process and send back the transaction details as xml datafeed. And logged all errors and complete information, so that we can see them through foxycart admin section by login and can maintain multiple stores.
Features list: http://www.foxycart.com/features-of-web-20-seo-ecommerce.htm
Features list: http://www.foxycart.com/features-of-web-20-seo-ecommerce.htm
Wednesday, July 28, 2010
Xcloner - For backup and restore Joomla, Drupal, Wordpress and All PHP/Mysql Websites
Hellow friends,
Xcloner is a tool to backup and restore feature for Joomla, Dupal, Wordpress and all PHP/Mysql Projects. You should should like xcloner for wordpress etc., in google for more info.
For Wordpress
http://www.devplug.net/
For Joomla
http://www.joomlaplug.com/Documentation/XCloner_Documentation/XCloner_-_Standalone_Backup_and_Restore.html
Xcloner is a tool to backup and restore feature for Joomla, Dupal, Wordpress and all PHP/Mysql Projects. You should should like xcloner for wordpress etc., in google for more info.
For Wordpress
http://www.devplug.net/
For Joomla
http://www.joomlaplug.com/Documentation/XCloner_Documentation/XCloner_-_Standalone_Backup_and_Restore.html
Monday, July 26, 2010
Use mysql_real_escape_string() function to avoid mysql injections
// Query database to check if there are any matching users
$query = "SELECT * FROM users WHERE user='{$_POST['username']}' AND password='{$_POST['password']}'";
mysql_query($query);
// We didn't check $_POST['password'], it could be anything the user wanted! For example:
$_POST['username'] = 'admin';
$_POST['password'] = "' OR ''='";
// This means the query sent to MySQL would be:
echo $query;
?>
The query sent to MySQL as:
SELECT * FROM users WHERE user='admin' AND password='' OR ''=''
This would allow anyone to log in without a valid password.
Solution:
// Query
$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
mysql_real_escape_string($_POST['user']),
mysql_real_escape_string($_POST['password']));
?>
Here mysql_real_escape_string function prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a to make data safe before sending a query to MySQL. So user can't hack your database.
$query = "SELECT * FROM users WHERE user='{$_POST['username']}' AND password='{$_POST['password']}'";
mysql_query($query);
// We didn't check $_POST['password'], it could be anything the user wanted! For example:
$_POST['username'] = 'admin';
$_POST['password'] = "' OR ''='";
// This means the query sent to MySQL would be:
echo $query;
?>
The query sent to MySQL as:
SELECT * FROM users WHERE user='admin' AND password='' OR ''=''
This would allow anyone to log in without a valid password.
Solution:
// Query
$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
mysql_real_escape_string($_POST['user']),
mysql_real_escape_string($_POST['password']));
?>
Here mysql_real_escape_string function prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a to make data safe before sending a query to MySQL. So user can't hack your database.
Saturday, July 24, 2010
Wordpress Vs Drupal
Hi, here is my view about where to use wordpress and where to use drupal.
Wordpress
# If your application doesn't contain so many dynamic content forms and have to manage some static pages of information and need a bloging system.
It should suitable company portfolio sites and simple to medium level websites.
Drupal
# If you have multiple dynamic content types (press releases, news articles, blog posts, etc.). Drupal is great at allowing you to create this stuff on the fly, with Wordpress you are hacking things together.
# If your site has more than a two template design structure (homepage and second levels).
# If you have numerous content blocks on the homepage or in sidebars that you will be editing frequently. Drupal’s block system is great at this kind of stuff.
# If you are trying to start small and expect your site to add tons of features/content moving forward.
It should suitable for complex websites which involves so many modules.
Wordpress
# If your application doesn't contain so many dynamic content forms and have to manage some static pages of information and need a bloging system.
It should suitable company portfolio sites and simple to medium level websites.
Drupal
# If you have multiple dynamic content types (press releases, news articles, blog posts, etc.). Drupal is great at allowing you to create this stuff on the fly, with Wordpress you are hacking things together.
# If your site has more than a two template design structure (homepage and second levels).
# If you have numerous content blocks on the homepage or in sidebars that you will be editing frequently. Drupal’s block system is great at this kind of stuff.
# If you are trying to start small and expect your site to add tons of features/content moving forward.
It should suitable for complex websites which involves so many modules.
Tuesday, July 20, 2010
Check session expiration in php
/* The below script will check for users inactivity on page, If use open one page, then store the current time on $_SESSION['start'] variable. If he doesn't move cursor or click any key from keyboard for some time, and then if he click on any link it will check his inactive time. if it is greater than the limited time we set here 5 minutes as exmple, then he will redirected to inactive.php page */
?>
session_start(); // NEVER FORGET TO START
$inactive = 300; //means expire within 5 minutes
if(isset($_SESSION['start']) ) { // if session start set
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive){ //if session time expired
header("Location: inactive.php"); //session expired message page
}
}
$_SESSION['start']=time(); //in pageload current time stored in session.
?>
?>
session_start(); // NEVER FORGET TO START
$inactive = 300; //means expire within 5 minutes
if(isset($_SESSION['start']) ) { // if session start set
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive){ //if session time expired
header("Location: inactive.php"); //session expired message page
}
}
$_SESSION['start']=time(); //in pageload current time stored in session.
?>
Recommended discussions forums for php
http://www.w3schools.com/
http://www.phpfreaks.com/forums/
http://forums.digitalpoint.com/forumdisplay.php?f=37
http://forums.devshed.com/php-development-5/
http://phpbuilder.com/board/
http://www.phpfreaks.com/forums/
http://www.weberforums.com/
http://www.phpbb.com/community/viewforum.php?f=1
http://www.sitepoint.com/forums/forumdisplay.php?forumid=34
http://phpdebutant.com/
http://www.phpfreechat.net/forum/
http://www.phpfreaks.com/forums/
http://forums.digitalpoint.com/forumdisplay.php?f=37
http://forums.devshed.com/php-development-5/
http://phpbuilder.com/board/
http://www.phpfreaks.com/forums/
http://www.weberforums.com/
http://www.phpbb.com/community/viewforum.php?f=1
http://www.sitepoint.com/forums/forumdisplay.php?forumid=34
http://phpdebutant.com/
http://www.phpfreechat.net/forum/
Enable SSH access for you shared hosting account in godaddy server
To Enable SSH on Your Linux Shared Hosting Account
1. Log in to your Account Manager.
2. From the Products section, click Web Hosting.
3. Next to the hosting account you want to use, click Launch.
4. In the Settings section of the Hosting Control Center, click the SSH icon.
5. Type your Country Code, Phone Number, and Extension (if applicable) in the corresponding fields and click Enable.
NOTE: SSH requires a strong password. If prompted to change your password, click Change Password, type a new password, and click OK.
6. We call the phone number provided within 10 minutes. Once the connection is established, an automated message plays a message containing a PIN. Type the PIN number into the You will be called with your PIN field and click Verify.
Once verified, it may take 24-72 hours for SSH to be enabled for your account. During this time, you are locked out from the account as it is moved to a new server.
1. Log in to your Account Manager.
2. From the Products section, click Web Hosting.
3. Next to the hosting account you want to use, click Launch.
4. In the Settings section of the Hosting Control Center, click the SSH icon.
5. Type your Country Code, Phone Number, and Extension (if applicable) in the corresponding fields and click Enable.
NOTE: SSH requires a strong password. If prompted to change your password, click Change Password, type a new password, and click OK.
6. We call the phone number provided within 10 minutes. Once the connection is established, an automated message plays a message containing a PIN. Type the PIN number into the You will be called with your PIN field and click Verify.
Once verified, it may take 24-72 hours for SSH to be enabled for your account. During this time, you are locked out from the account as it is moved to a new server.
Thursday, July 15, 2010
PHP For Android
Hi Friends,
PHP For Android project was launched recently and the complete information available in phpclasses.org site in the form of interview with the inventor. The information url: http://www.phpclasses.org/blog/post/125-Developing-PHP-applications-to-run-natively-on-Android-phones.html
PHP For Android project was launched recently and the complete information available in phpclasses.org site in the form of interview with the inventor. The information url: http://www.phpclasses.org/blog/post/125-Developing-PHP-applications-to-run-natively-on-Android-phones.html
Wednesday, July 14, 2010
Agile method in software development
Agile method is nothing but building software with incremental or interactive work strategies known as sprits i.e building application by involving number of people or teams and push the work into public when considerable amount of work done. And can be able to roll back to any previous version of the application if found any thing wrong or unhappy with the new version of the appliction when some one or team push their work recently.
This approach is the better one when compare to waterfall, or traditional sequential development.In older days A project could be developed much like an automobile on an assembly line, in which each piece is added in sequential phases. This means that every phase of the project must be completed before the next phase can begin. Thus, developers first gather all of a project's requirements, then complete all of its architecture and design, then write all of the code, and so on.
In this scenario, If any thing went wrong in the development stage, can't revert it back and company has spent time and money to create a software that no one wants.
Whereas agile methodology helps a lot to the interactive development mode.
This approach is the better one when compare to waterfall, or traditional sequential development.In older days A project could be developed much like an automobile on an assembly line, in which each piece is added in sequential phases. This means that every phase of the project must be completed before the next phase can begin. Thus, developers first gather all of a project's requirements, then complete all of its architecture and design, then write all of the code, and so on.
In this scenario, If any thing went wrong in the development stage, can't revert it back and company has spent time and money to create a software that no one wants.
Whereas agile methodology helps a lot to the interactive development mode.
Build IPhone native appliactions with PHP or Ruby code
If you wanna develop IPhone native applications and don't have the time to learn completely new language i.e Objective - C, Now it is possible for the PHP and Ruby developers. By using one third party service you can write code in either PHP or Ruby and build native IPhone application also can use Html and CSS for UI Design.
You can download the source from here : http://www.appcelerator.com/
Other available tools to develop Iphone and wap applications.
You can download the source from here : http://www.appcelerator.com/
Other available tools to develop Iphone and wap applications.
Monday, July 5, 2010
Backup database using php code
Hello Frineds,
Below code would take entire database backup and store it in the current folder. You can run this script automatically using crop job, so that you would have your database backup for every day or every week as you wish.
//backup_tables('localhost','root','rot','database_name','table_name'); //To backup one specific table
backup_tables('localhost','root','rot','database_name'); // To backup entire database
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
//save file
$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
?>
Below code would take entire database backup and store it in the current folder. You can run this script automatically using crop job, so that you would have your database backup for every day or every week as you wish.
//backup_tables('localhost','root','rot','database_name','table_name'); //To backup one specific table
backup_tables('localhost','root','rot','database_name'); // To backup entire database
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
//save file
$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
?>
Difference between echo & return statements in function
Hi,
Here is the explanation about where we should use echo and where we should use return statements while working with functions.
If you want to print some thing on browser and continue execution of the process then you have to use echo statement.
Ex:
function test()
{
static $count = 0;
$count++;
echo $count;
if ($count < 10) {
test();
}
$count--;
}
test();
?>
Here static variable is initialised only once when first called the test function and then it will maintain the value of $count till the end of the process.
O/P:12345678910
When you use the return statement the program execution stopped in that line and output some thing to the variable. So Calling return in your script or function will either end the script or end the function and then return the value
Ex:
function test($arg)
{
if ( $arg == 'ban' ) {
return 'Banana';
}
else
{
// There's nothing else to do, so end execution of this function
return;
}
}
$fruit = test('banana');
if ($fruit=='Banana')
{
echo 'Banana';
}
?>
Here is the explanation about where we should use echo and where we should use return statements while working with functions.
If you want to print some thing on browser and continue execution of the process then you have to use echo statement.
Ex:
Recursive functions with static variables
function test()
{
static $count = 0;
$count++;
echo $count;
if ($count < 10) {
test();
}
$count--;
}
test();
?>
Here static variable is initialised only once when first called the test function and then it will maintain the value of $count till the end of the process.
O/P:12345678910
When you use the return statement the program execution stopped in that line and output some thing to the variable. So Calling return in your script or function will either end the script or end the function and then return the value
Ex:
function test($arg)
{
if ( $arg == 'ban' ) {
return 'Banana';
}
else
{
// There's nothing else to do, so end execution of this function
return;
}
}
$fruit = test('banana');
if ($fruit=='Banana')
{
echo 'Banana';
}
?>
Friday, July 2, 2010
PHP start session only once to prevent warnings
session_id() returns an empty string if there is no current session, so to test if a session already exists, its better to write this :
if(session_id() == "")
{
session_start();
}
else
{
// Anything you want
}
if(session_id() == "")
{
session_start();
}
else
{
// Anything you want
}
Thursday, July 1, 2010
Get current page URL along with SSL protocal and port number In PHP
Hi, Below code will get the current page URL along with SSL protocal and port number
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
echo curPageURL();
?>
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
echo curPageURL();
?>
Monday, May 17, 2010
Free hosting for php mysql applications
Free hosting for php,mysql applications with no ads, no hidden charges. Provides control panel. cpanel and FTP etc.,
http://www.000webhost.com/307968.html
http://www.000webhost.com/307968.html
Tuesday, April 20, 2010
Get full url with http or https protocol
/**
*
* @get the full url of page
*
* @return string
*
*/
function getAddress()
{
/*** check for https ***/
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
/*** return the full address ***/
return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
/*** example usage ***/
echo getAddress();
?>
Subscribe to:
Posts (Atom)