Adapter pattern in php

Can we Adapt SMS into MAIL?
Now we’re going to do an impossible task.
Are you prepared?
Can we start?
This chapter is about the adapter pattern. It’s one of the design patterns that you’re currently on. Let us start with a real world example.
You know that internet connection is absolutely necessary for sending emails. Is it true in the real world? You’d say, well, I know that. An internet networking is a must.

Continue reading “Adapter pattern in php”

What to start with, ASP.NET or PHP?

For further reading, more php and asp.net codes please go to Sanjib’s Scribble
********************
Well, I’d like to write about this in INDIAN context. That is, I presume, you are about to start your journey as a web developer in India, and thinking about learning a web language. Now, keeping this condition in mind, what you’ll do? What will you learn first? And why this but not that?
I’ll keep writing it in several parts. Because I have not enough time and bandwidth in my data card to keep going on for a long journey, but I promise I’d keep it as short as possible.
Before starting I’d apologize for not including Python, Java or Rubi on Rails in my discussion mainly for two reasons.
1) I don’t know them.
2) For dynamic web site, the competition is fierce between these two technology and I have some live experiences about them.
If you are Indian, PHP is the best options for you to start. Not ASP.NET. Why?
Let me write down the reasons first. Next I’ll explain them in detail. I don’t claim, that this is final judgement and won’t suggest you to follow my reasons blindly. What I write, writing from a realistic point of view. You may agree or disagree. Whatever your opinion I’d like to get your comments.
Here are the reasons why PHP is better to start with.
1)Cost effective.
2)Open source.
3)Simplicity.
4)You don’t have to buy any software.
5)A good demand in small or medium company.
6)Takes less time to learn and start with.
7)Compactness and simple integrity with MySql database.(If you can conceptualize array, 50% job has been done!)

Now I’d like to clarify from my experience. One by one.

1) Cost : As a web developer, you’ll find that cost will play a very important role in the future. Whenever, you’d like to contact a hosting company they will always ask more money for a windows hosting which is needed for ASP.NET. For PHP you need Linux hosting that is almost half the amount for the same space and bandwidth. In Windows, it takes more cost because you need to hire an extra SQL Server. In PHP, MySql is in-built. So you need not spend extra dime for it. Form my experience I can say, in Linux hosting there are other advantages or features like blog, wiki, E-Commerce, image gallery projects like wordpress, phpbblog etc. In windows hosting you can not take advantage of such open source frameworks. What ever you want to do in ASP.NET, you have to do single handedly.
Some will argue here, there are many starter kits and open source projects available in ASP.NET also that you can download free from asp.net official site. Then where is the difference?
The difference is in installation process. In ASP.NET you may find some open source projects like blog, wiki etc. But to install them in a separate folder is quite cumbersome. On the contrary, WordPress or PHPBB type projects(run in php and MySql) are ready to install easily and quite user friendly.
So LAMP is not cheap in that sense but cost-effective.
2) Open Source
PHP/MySql is Open Source. If you want to learn more about it, please google it or read Wikipedia. You’ll get more idea about it. Basically it means, it is free, easy to use and there are much more free support from the community in every step. You can also edit the source code that you get from elsewhere.
3)Simplicity
ASP.NET is more user friendly, no doubt. But, if you want to learn the basic, core ideas on which the passage of data depends, then PHP is the best bet. If you can conceptualize array, then 50% job has been done.
4) You don’t have to buy any software.
To learn PHP/MySql you need not buy any software. This is free and that is why it is so much popular.
5)A good demand in small or medium company.
As the job market is concerned, small or medium level companies opt for free open source softwares. So PHP developers are in demand always.
6)Takes less time to learn and start with.
If you are from a computer background learning PHP is much easier. Logic plays a vital role. If you can follow the logic, how the logic flows, how data transfered from one page to other through array(name=>value) combination, the job has been done.
7)Compactness and simple integrity with MySql database.(If you can conceptualize array, 50% job has been done!)
The best friend of PHP is MySql. They are like Marx and Engels. You may type SQL in your PHP page and get the desired effect in your web page. Also, the hosting companies come with this great combinations so you start with an advantage.

ASP.NET and PHP, a basic difference

In ASP.NET you need to declare data type of variable explicitly. Like int num; that means num variable knows how much place it will hold in memory. It could be string str; float flt etc. But in PHP you need not do that. Usually you write $number to declare a integer variable.
So it is wise to pick up variable name so that it will mean either integer or string.
In PHP when you take up someone’s name you may write $name. It could be a string.
Actually what happens, PHP engine interprets the variable according to the value you are assigning it. That makes it operative part a little bit easier.
The CRUD concept is present in both. But, in ASP.NET it is more complicated and divided into many sections. Of course, people who know ASP.NET, may find it more organized too.
Lastly, due to windows, ASP.NET gives you a desk top experience and much more user friendly. If PHP gets something like this (I know nothing about zend framework although), it will be unstoppable and unparalleled due to its Open Source Presence.
Lastly, to host a ASP.NET site is more costly than PHP, and other Open Source helps make PHP much more desirable.

ASP.NET and PHP

I started this blog mainly with a plan – I’d try to evaluate ASP.NET and PHP, tracing a honest comparison between these two great programming languages.
Frankly speaking when I tried to do my hands dirty with codes, I found that I have still miles to go in PHP specially. I’m still learning ASP.NET, but about PHP I’m still lurking in darkness. So I’d better have a grasp first.
One thing I can say for sure, PHP is easier to pick up and easier to implement.
If you consider The OOP part, Object Oriented part of ASP.NET will take some time to learn and understand and it gets complicated a little bit with newly built classes belong to App_Code folder and calling them into Page class and run methods.
In PHP, just use include method anywhere, either in the class where you’d like to call a function from another class or include in your PHP page.
So OOP seems bit easier to me in PHP than ASP.NET.
I’d like to write more about it later.

How to set Roles and access to certain pages

In ASP.NET forum very often a question is asked. How to set Roles and accordingly restrict access to certain pages?

There are definitely various ways. But I prefer UserControl. Its advantage is you can drag it to the Masterpage and its functionality has been used all along your application.

Here the main problem is I can’t use the code so I upload codes as Images part by part.

Here is the code:

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

Here I used few controls like LoginView, LogInStatus and lastly in the Page_Load event handler I checked whether User.Identity.IsAuthenticated. It can be used as User.IsInRole also to check the user belongs to a certain Role or not.

In this way, one can check whether a user belongs to the Role Administrator or Member, if he/she is Administrator can go to CatalogAdmin.aspx and if he/she belongs to the Role of  Member, then he/she might have access to Member_1.aspx page.