Get Current URL using PHP

The other day I was writing a script where I was required to consume the current webpage url for in the services I was writing. PHP Server variable is quiet handy for such scenarios as it provide all the parameters passed through the server. Though direct information about the current URL is not provided, it can be formed using the following script:

Add the following code to a page:

<?php
function getCurrentWebpageURL() {
	$pageURL = 'http';
	if ($_SERVER["HTTPS"] == "on") {
		$pageURL .= "s";
	}
	$pageURL .= "://";

	if ($_SERVER["SERVER_PORT"] != "80") {
		$pageURL .= $_SERVER["SERVER_NAME"];
		$pageURL .= ":".$_SERVER["SERVER_PORT"];;
		$pageURL .= $_SERVER["REQUEST_URI"];
	} else {
		$pageURL .= $_SERVER["SERVER_NAME"];
		$pageURL .= $_SERVER["REQUEST_URI"];
	}
	return $pageURL;
}
?>

You can now get the current page URL using echo/var_dump or can consume the same directly by assigning to a variable:

<?php
  echo getCurrentWebpageURL();
?>

More details about PHP server variables can be find at http://php.net/manual/en/reserved.variables.server.php

To check out the current values of Server variables, var_dump ($SERVER) can be a handy trick as well.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Life without Facebook

Recently I deactivated my Facebook account for some personal reasons. It was something which was really hard and the addiction to check or spend time surfing Facebook was too compelling, yet I managed to do that somehow. (Did I hear someone patting my back…J )

Life without Facebook, this post summarizes my experiences without Facebook in last couple of days and how I see the future with/without Facebook.

1. Free music is kind of dead: Unless you are a guy with a cap with skulls and bones (typical pirate-wear), you must be using free music providers like Spotify or Saavan (There are some rich people who purchase music quiet often too, but for this case we are considering the others). Spotify/Saavan both use Facebook sign in, where Spotify had made it compulsory to have Facebook account to access Spotify. And here I go stumped, suddenly I lost all the music I had accumulated at Spotify. And though Saavan can be used without Facebook, it is yet to grow to the heights of Spotify and there is no doubt if Facebook wants to partner with Saavan with some funding to enable single sign in using Facebook only, Saavan being a startup would definitely like to embrace the offer.

2. Social networking for Job Search: I am fond of LinkedIn, Glassdoor and Bullhorn for maintaining my professional network and updates regarding new opportunities in my field. One of the days while browsing Glassdoor, I got a message “Sign in with Facebook account” to read more. Fortunately, Glassdoor had login via your credentials apart from Facebook login.

3. Event Invite: This was not the first party/event I missed in last few days. Facebook has evolved as the RSVP de-facto. Organizing a party, create an event and voila you are done.

4. Facebook Applications: developed by you, you lose them as well. Probably it’s a good idea to create a Facebook developers account separately from your personal account.

I believe there is lot more to experience, but one thing is for sure, Facebook has secured a strong place over the web. I still love Facebook and admire the scalable system design they have to handle over 1 Billion accounts. It is undoubtedly one of the best social network that have been around. But I am scared about the path leading the dependency with Facebook, and hope alternates shall be used by web services for consumers who does not want to use Facebook services.

Note: This Post is still under construction might be adding, editing the post with my experiences.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Windows 8 Surface RT vs Pro

Past few days have been very exciting for Microsoft fan boys, I admit I am being one of them. With the availability of Surface tablet, Windows 8 RTM (General Availability), Office 2013 (for MSDN/Technet), Windows Phone 8 event in pipeline next week, things have never been exciting and bright for Microsoft. I personally admire how Microsoft has come through the “Vista Phase” where tech-pundits were predicting death of OS to the current phase.

The recent announcement of Microsoft Surface Tablet RT version was one which everyone was looking for due to rumors like pricing to be as low as $200 to compete with tablets in the same segment. The price rage though affordable than Apple’s iPad, were not cheap enough to suddenly turn the market share in favor of Microsoft, probable reason being Microsoft had to make sure not to displease tablet manufacturers for Windows 8.

Though the announcement for Surface RT was appreciated, there were some doubts regarding Surface RT vs Pro. This post shall clear the doubts before you buy Surface.

Read more »

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Resolve Cisco AnyConnect VPN Client error on Windows 8

I have been early adapter of Windows 8. since the dev preview in Sept 2011. close to 9 months and we still have not seen the RTM which would probably be out in October for general public. So apart from bragging my geekiness i try to earn my bread n coffee using coding. One of days i brought some work to home to leverage Work from Home advantage but was disappointed to see Cisco VPN client was not working with Windows 8. It displayed an error while i was trying to connect to my corporate network:

“The VPN Client driver has encountered an error.” or “Cannot initiate VPN.”

Some forums misguided me VPNClient does not works on Windows 8. Also to make sure i tried to dog the old dieing OS on my machine that was Windows 7 and found out VPN Client working there. This narrowed down my problem to Windows 8 vs Cisco VPNClient compatibility. After a lot of searching digging mining turned out there is a quick and easy fix for this.

1. From the Start screen type “regedit” or Windows Key+R shortcut and type “regedit” to launch the Registry Editor.

2. Give it admin rights when UAC prompts.

3. In the registry editor, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\vpnva

4. Double-click on the DisplayName key, and remove the INF information from the display name so the modified version appears as Cisco AnyConnect VPN Virtual Miniport Adapter for Windows x64. (or the 32-bit / x86 equivalent)

5. Click OK. Close Registry Editor and launch the AnyConnect client. The connection should work normally.

No reboot required and i am connected to my corporate Network. Thanks Tom for the tip.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to use Smarty variables in Javascript Code

Smarty

Smarty is a template engine for PHP that facilitates a managable way to separate application logic and content from its presentation. This is mostly used in industrial architecture following MVC (Model View Controller) architecture. The application data that contain no information about how they will be presented. They are passed into Smarty by the application, then the template designer edits the templates and uses a combination of HTML tags and template tags to format the presentation of these elements. Smarty ensures programmer can make changes to the application logic without the need to restructure templates, and the template designer can make changes to templates without breaking application logic.

Smarty is used in *.tpl files. These tpl files can use web presentation technologies like HTML and Javascript. While working recently in a web page rendered by Smarty while using the code , It threw the following error

The specific message was: Syntax Error in template “/websites/site.local/views/manager/index.tpl” on line 564 “onclick : function() {” – Unexpected ” : “, expected one of: “}”

Now this error might look a bit weird, since you can easily access variables passed from PHP code using {variableName}

However, while using smarty variables inside a javascript, the Javascript code should be enclosed using the {literal}{/literal} tag if you haven’t. This prevents Smarty from parsing what’s in between so that the Javascript code is not being mistaken for PHP code.

So the code can look like :


{literal}

{/literal}

Smarty is a neat way to separate your code. I am still learning it and enjoying working over it. If you have nay questions regarding SMARTY you can ask by commenting here… More about Smarty: http://smarty.incutio.com/?page=SmartyFrequentlyAskedQuestions#basics-1

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Difference between INT(1) vs TINYINT(1) in MySQL

The other day while designing a database schema i was suggested to use Tinyint instead of int. Tinyint, never ever used in SQL. So i digged a bit about this datatype. Later i thought probably i can use INT(1) for declaring the database field rather than TINYINT(1) as both might be restricted to a single digit only. Yes they would. But representation of TINYINT(1) is not exactly this. I’ve always just used INT(1) to say it’s an integer and it will only be one digit, which I assume means it could only be a value 0 through 9.

So, is there any difference between the various integer types INT, TINYINT, SMALLINT, MEDIUMINT, and BIGINT if you define a length of 1 for each type? And the answer is Yes there is a big diffeence between these data types though they belong to same class.

The number in parentheses for integer column types is the “display width”. This does not effect the storage requirements as they are pre-defined. INT(1) does not allow only one character, infact it sets the display width for that column in result sets. The display width is a number from 1 to 255. You can set the display width if you want all of your integer values to “appear” similarly. So INT(5) will not hold maximum value as 99999 but it will set the width of number as 5 for display and will truncate more or pad with space if less.

As an example quoted from Matthom

INT(6) sets the display as:

55
643
1098
81153

where the left side are padded with spaces.

To help visualize it easier, try this:

_ _ _ _ 5 5
_ _ _ 6 4 3
_ _ 1 0 9 8
_ 8 1 1 5 3

Notice how they all have a display width of 6.

Also, notice the datatype range and size would be different for int and tinyint. While int takes 4 bytes, tinyint takes just a single byte.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Windows 8 Tablet Preview

Windows 8 has mixed opinions at the moment. While many appreciate the new look, others find the double interface system a drag. Yet, Windows 8 is pretty much about touchscreen devices from start to finish. Microsoft has taken time to create something that’s amazing. Although it’s not out as yet, it’s still the main talk in town. There’s a lot to look forward to on Windows 8 tablets.

Running On ARM, Intel and AMD Chips
Windows 8 runs on x86 based Intel and AMD machines and also has the capacity to run on ARM-based hardware. Apple and Android tablets run on the same kind of hardware. Plenty of interesting kits can be expected after the release of Windows 8. If things go according to the plan, Windows 8 for ARM tablets and Windows 8 for x86 PCs should be launched together. One of the test beds for the new ARM-based tablets is the Tegra 3 chip by Nvidia. Microsoft has partnered with Nvidia to bring in high performance to Windows 8. The only issue here is that the ARM-based Windows 8 won’t really have any desktop apps except Metro apps, thus, rumors suggest that only a few tablets will be launched.

The New Metro Interface
Windows 8 tablets will have a brilliant interface called Metro. This interface is just like the Windows Phone 7. Advanced, smooth, vibrant, the whole experience has been totally transformed, while the power, elasticity and connectivity stay perfect. Even thought Metro is mainly designed and optimized keeping touch in mind, it works remarkably with a mouse and keyboard as well. This gives users the ability to use the device they prefer, the peripherals they opt to use and run the different apps their crazy about. This in-turn, will lead to a new generation of hardware and software. When it comes to portrait orientation, the Windows 8 tablets demonstrated so far have been in landscape.

Tablet Desktop
The new ARM version Windows 8 tablets have the Metro interface and the traditional desktop. However, only third-party Metro apps are allowed. The windows desktop and known apps like Internet Explorer, Windows Explorer, Windows Live and Office. All the other apps will be Metro.

Start Menu
Windows 8 doesn’t have a Start button or Start Orb as it’s known. The start button is replaced with the new Metro Interface. Microsoft might face a small repercussion with this, yet, Microsoft stand by the Start Menu decision made in Windows 8.

Windows App Store
The web will be moved with different app development and Microsoft is sure about that. So much so, that a Windows Store has been created with entrances that are manufacturer specific. In-fact, apps play in huge role in Windows 8. Several Metro apps will be pre-installed on Windows 8, which deal with elements like messaging, calendar, SkyDrive, mail, photos, videos, people, music and a camera. The apps will be in the Windows Phone Metro style, while some apps like messaging may include mobile aspects like SMS support.

Tablet Display
Windows 8 happily supports a 10.1-inch tablet display along with a 291dpi. The new iPad has 265 dpi. Thus, tablet display with HD resolution will be a standard feature offered by Windows 8 tablets. Everything displayed by this OS will be totally awesome.

High End Support
Windows 8 is a high end operating system. Nvidia has joined hands with Microsoft knowing the fact that Windows 8 has a lot to offer and a long way to go. This new Microsoft creation is completely trusted by Nvidia and several others for that matter. Motorola is ready to use Windows 8 as its main platform. There are vendors who don’t mind moving away from Android and opting for Windows 8. Windows 8 has many supporters and that stand by it, knowing that it an amazing innovation that will change many things.

Tablet Manufacturers
At Microsoft’s Build conference, a Samsung tablet with Windows 8 OS was shown. HP also intends to make Windows 8 tablets. Windows 8 has a lot of potential and that’s something Dell agrees to, after checking out the amazing capabilities in Windows 8 Beta. Dell has opted to use Windows 8 in its new tablets that will be launched during the second or third half of this year. Nokia has also planned to release a Widows 8 tablet towards the end of this year, or the start of 2013, as it considers it to be an incredible opportunity.
Nokia intends to create a tablet that can fight head to head with the iPad. Asus will sell its Windows 8 tablets in the third quarter of 2012. There are many manufacturers that will design window 8 tablets for business proposes.

Price Tag
It is obvious that Windows 8 and iPads, Android tablets along with Chrome OS netbooks will fight to be the strongest. They have to be priced in the best way possible in-order to sell, as the options of style and features and performance will come head to head.

Windows 8 is definitely the new buzz that consumers as well as manufacturers are waiting for. It does have a lot to offer and a Windows 8 tablets will probably overtake all their rivals. However, too much shouldn’t be expected at the moment, as when Windows 8 tablets are finally out, they won’t be appreciated that much. One thing’s for sure, Windows 8 is here to stay and Windows 8 tablets are going to be totally remarkable and extreme.
About the author: Brianne Walter is a blogger who also happens to be a tech freak. She loves spending on tech stuff and is a gadget freak who like to write articles on latest gadgets like Samsung Omnia W smartphone, hp envy 17 etc.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Indexing documents in Solr with custom fields

A lot of time i spent this weekend for indexing documents into Solr. And i was really unhappy with the community support provided by Apache mailing list. I believe Apache has some really nice software packages and frameworks that are very useful for developers and enterprises, but it all boils down to community support if a product is being preferred in the developer world.

Solr, is a search platform by Apache Lucene project. It is used for full-text search and indexing. All those familiar with search engines must be knowing, how a search engine like Google provides us results.

Initially, fed with a seed file containing URLs, the search engine keeps on parsing these files (webpages) and putting all URLs into a stack. After reading each file it pops another webpage from stack and parses its URL and this goes on. During this crawling phase, all URLs interlinked to a page can be crawled. Apache Nutch is a software which can be useful for such purposes. Spider or Bots for Search engines are sued for crawling the web.

The next step for a search engine, is indexing those documents the functionality which can be provided by Solr. After indexing webpages, which are stored using an inverted index data structure, Search engine’s next step is displaying query results. These results are displayed on basis of propriety algorithms of search engines like page rank or some biasing of the results (for which Google has been recently criticized a lot).

So indexing is a very important steps in Web search engines, and often documents are indexed using tags. For indexing in Solr using custom fields, one may need to follow these steps:

1. Navigate to Solr installation folder, in my case it was inside xampp\solr\conf\ . Here in the schema.xml file the field to be indexed is added. with its properties. The schema.xml file contains all of the details about which fields your documents can contain, and how those fields should be dealt with when adding documents to the index, or when querying those fields.

Thesection inside shema.xml file is where you list the customdeclarations you wish to use in your documents along with various field options that apply to a field.

Common options that fields that can be customized are…

 

1. default

The default value for this field if none is provided while adding documents

2. indexed=true|false

True if this field should be “indexed”. If a field is indexed, then it is searchable, sortable, and facetable.

3. stored=true|false

True if the value of the field should be retrievable during a search

4. compressed=true|false

True if this field should be stored using gzip compression.

5. compressThreshold=

6. multiValued=true|false

True if this field may contain multiple values per document, i.e. if it can appear multiple times in a document

7. omitNorms=true|false

Set to true to omit the norms associated with this field (this disables length normalization and index-time boosting for the field, and saves some memory). Only full-text fields or fields that need an index-time boost need norms.

8. termVectors=false|true

If set, include full term vector info.

If enabled, often also used with termPositions=”true” and termOffsets=”true”.

9. omitTermFreqAndPositions=true|false

If set, omit term freq, positions and payloads from postings for this field. This can be a performance boost for fields that don’t require that information and reduces storage space required for the index. Queries that rely on position that are issued on a field with this option will silently fail to find documents.

10. omitPositions=true|false

If set, omits positions, but keeps term frequencies

To include two fields in the document which i am reading, i wanted them to index using their Author Name/ Maximum frequency term. To add these fields i simply added the code in the schema.xml under the

<field name="AuthorName" type="string" indexed="true" stored="true" required="true" omitNorms="false" default="defAuthor"/>
<field name="MaximumFrequencyTerm" type="string" indexed="true" stored="true" required="true" omitNorms="false" default="testLong"/>


Once done with editing, schema.xml, the necessary code to index files using SolrJ API for Solr is :


SolrServer server = new CommonsHttpSolrServer("http://localhost:8080/solr/");
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
SolrInputDocument doc = new SolrInputDocument();
doc.addField("MaximumFrequencyTerm", MaximumFrequencyTerm,35);
doc.addField("AuthorName", AuthorName,35);
Collection docs = new ArrayList();
docs.add( doc );
server.add( docs );
server.commit();

Make sure to add any unique keys along with to add in the document before you commit. Once you run the code all files are indexed with the custom field and can be seen in the Solr search at http://localhost:8080/solr/admin using the search query as “*:*” .

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Installing Solr over Windows

In the last post, i covered how to troubleshoot Xampp port error for configuring Tomcat Apche Server on Windows. In this post i would be covering on How to install Solr on Windows.

Solr is an open source enterprise search platform from the Apache Lucene project written in Java. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, and rich document (e.g., Word, PDF) handling. Providing distributed search and index replication, Solr is highly scalable. Solr runs as a standalone full-text search server within a servlet container such as Apache Tomcat. Solr uses the Lucene Java search library at its core for full-text indexing and search, and has REST-like HTTP/XML and JSON APIs that make it easy to use from virtually any programming language. (Wiki)

Steps to install Solr on windows:

1. If you have successfully installed Tomcat Server (using Xampp probably), try opening localhost:8080. If this shows a page with message “If you’re seeing this page via a web browser, it means you’ve setup Tomcat successfully. Congratulations!” , you are good to go to second step. We assume tomcat has been installed under D:\xampp\tomcat

2. Download and unzip the Solr distribution zip file into a temp folder at D:\temp\solrZip\
Latest build (As of Apr 16, 2012) can be downloaded from here : http://mirrors.axint.net/apache/lucene/solr/3.6.0/apache-solr-3.6.0.zip

3. Create a directory as “solr home” directory called, where you intend the application server to function, You may create it inside xampp installation directory itself at
D:\xampp\solr

4. Copy the contents of the example\solr directory D:\temp\solrZip\example\solr\ to D:\xampp\solr\

5. Stop the Tomcat service

6. Copy the *solr*.war file from D:\temp\solrZip\dist\ to the Tomcat webapps directory D:\xampp\tomcat\webapps\ and rename the *solr*.war file solr.war

7. Configure Tomcat to recognize the solr home directory you created, by adding the Java Options -Dsolr.solr.home=D:\xampp\solr\ and -Dsolr.velocity.enabled=false
either use the system tray icon to add the java option
or manually edit the environment script D:\xampp\tomcat\bin\setenv.bat and add it to JAVA_OPTS

* Note: For Tomcat 7 and Solr3.6, the above option on setenv.bat may not work, so you could not use it and put this code fragment
on $CATALINA_HOME/conf/Catalina/localhost/solr.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="D:\xampp\tomcat\webapps\solr.war" debug="0" crossContext="true" >
<Environment name="solr/home" type="java.lang.String" value="D:\xampp\solr\" override="true" />
</Context>

8. Start the Tomcat service

9. Go to the solr admin page to verify that the installation is working. It will be at http://localhost:8080/solr/admin

You are good to go with Solr over Tomcat now.. .

Sources: http://wiki.apache.org/solr/SolrTomcat#Tomcat_on_Windows

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

XAMPP Installation Error: “Port 80 or 443 already in use.Apache2.2 service failed.”

XAMPP is a powerful application to setup server on your local machine for testing of your files before you host them to the server. Installation of XAMPP is pretty simple but it went tricky for me. It gave an error “Port 80 or 443 already in use.Apache2.2 service failed.” to me while installing Apache Tomcat and MySQL via XAMPP.

This error may encounter if you are already using port 80 which is done if you have already deployed a server (IIS probably) on your local machine. However, i had not installed IIS. And the reason was i have installed SKYPE on my machine which by default utilizes port 80. It’s a known issue that if Skype was installed before XAMPP it will occupy port 80 to communicate with your Internet connection.

Fix for this Problem:

Open up Skype and go to Tools and select Options. From the list that appears select Advanced and then Connection. There will probably be a check mark inside where it says “Use port 80 and 443 as alternatives for incoming connections” just unchecked that box and save your changes. Skype will still function normally and now XAMPP will be able to use port 80 to run.

Also if the problem is still not resolved, check hosts file in Windows directory. Hosts files are used by windows os to map their addresses.

Host file is located at: c:\windows\system32\drivers\etc\hosts

Your host file must look like this :

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost

If not make appropiate changes. (You may require admin privileges to make changes to this file.)

Now open up your browser and type this in your address bar:
http://localhost/ and press enter.

It will bring the “Welcome to the XAMPP index screen.”

Still not resolved or some other solution worked for you ? Let me know in comments…

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
http://www.windowsvj.com/outlet