|
Please, oh Google-gods, rank this blog prominently, and let's save some poor, misguided souls who might be searching for some code on formating a query string in C# or merely grazing for urdu shayaris.... If just one person sees the light, then I've done my job! .... Yes, I am not above shamelessly begging the search engines for relevance .... it's called SEO, right?)
Wednesday, June 6, 2007
Tuesday, June 5, 2007
HT Access file
htaccess-file
The name of the file is .htaccess (Its the extention with no name).
A .htaccess-file is a files that lets you do a whole lot off security tricks:
- Custom error pages
- Preventing a directory from being listed
- Password protection
- Deny users by IP
- Change your default directory page
- Prevent viewing of .htaccess file
- Redirects
- Adding MIME types
- Preventing hot linking of your images
You can't create .files in windows (You can, but its hard). Give them another name and rename them on the server.
You can write .htaccess in notepad (or any other simple-text editor). Remember to turn off wordwrap.
If you are using Microsoft FrontPage extensions you shouldn't edit the .htaccess -document.
.htaccess files must be uploaded as ASCII mode, not BINARY.Custom error pages
Below is a list of the server returned error codes that are most seen by users.
Error document codes (most used)
400
Bad Request
401
Authorization Required
403
Forbidden
404
Not Found
500
Internal Server Error
400 - Bad Request, which is one of those generic kind of errors that people get to by doing some weird stuff with your URL or scripts.
401 - Authorization Required (as in when somebody tries to enter a protected area of your site without the proper credentials)
403 - Forbidden (as in when a file with permissions not allowing it to be accessed by the user is requested)
404 - Handle requests for pages that are not found.
500 - Internal server errors in any scripts you have currently running.
In order to specify your own customized error documents, you simply need to add the following commands, on one line, within your htaccess file:
ErrorDocument 404 /errors/notfound.html
You can name the pages anything you want and you can place the error pages anywhere you want within your site, so long as they are web-accessible (through a URL). The initial slash in the directory location represents the root directory of your site, that being where your default page for your first-level domain is located.
You can specify a full URL rather than a virtual URL in the ErrorDocument string (http://yoursite.com/errors/notfound.html vs. /errors/notfound.html). But this may not be the preferred method by the server's happiness standards.
You can also specify HTML with your error documents.
ErrorDocument 401 "<body bgcolor=#ffffffglt;<h1> You have to actually <b>BE</b> a <a href="#">member</A> to view this page!</h1></body>"Preventing a directory from being listed
Do you have a directory full of images or zips that you do not want people to be able to browse through? Typically a server is setup to prevent directory listing, but sometimes they are not. If your server is not, you will have to become self-sufficient and fix the problem with htaccess:
IndexIgnore *
The * is a wildcard that matches all files
Place that line into an htaccess file in your images directory and nothing in that directory will be able to be listed.
What if you wanted the directory contents to be listed, but only the HTML pages and not the images?
IndexIgnore *.gif *.jpg
This would return a list of all the files except those specified in the above example.
If your server is setup to prevent directory listing and you want your directories to be listed then you could simply put this into the htaccess file:
Options +Indexes
If you do use this option, be very careful that you do not put any unintentional or compromising files in this directory. You can put in a minus sign (Options -Indexes) to prevent directory listing entirely. This is typical of most server setups and is usually configured elsewhere in the apache server, but can be overridden through the use of htaccess.Password protection
There are numerous methods to password protecting areas of your site with some server language based (such as ASP, PHP or PERL) and client side based, such as JavaScript. JavaScript is not as secure or foolproof as a server-side option. A server side challenge/response is always more secure than a client dependant challenge/response. Htaccess is about as secure as you can or need to get in everyday life.
The first thing you will need to do is create a file called .htpasswd. I know, you might have problems with the naming convention, but it is the same idea behind naming the .htaccess file itself, and you should be able to do that by this point. In the .htpasswd file, you place the username and password (which is encrypted) for those whom you want to have access.
Example:
username:encryptedpass
There is a handy tool to easily encrypt the password at http://www.euronet.nl/~arnow/htpasswd/
For security, you should not upload the htpasswd file to a directory that is web accessible (yoursite.com/.htpasswd), it should be placed above your www root directory. You'll be specifying the location to it later on, so be sure you know where you put it. Also, this file, as with htaccess, should be uploaded as ASCII and not BINARY.
Create a new htaccess file and place the following code in it:
AuthUserFile /usr/local/you/safedir/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require user username
The first line is the full server path to your htpasswd file. If you have installed scripts on your server, you should be familiar with this. Please note that this is not a URL, this is a server path. Also note that if you place this htaccess file in your root directory, it will password protect your entire site, which probably isn't your exact goal.
The second to last line require user is where you enter the username of those who you want to have access to that portion of your site. Note that using this will allow only that specific user to be able to access that directory. This applies if you had an htpasswd file that had multiple users setup in it and you wanted each one to have access to an individual directory. If you wanted the entire list of users to have access to that directory, you would replace Require user xxx with require valid-user.
The AuthName is the name of the area you want to access. It could anything, such as "EnterPassword". You can change the name of this 'realm' to whatever you want, within reason.
We are using AuthType Basic because we are using basic HTTP authentication.Deny users by IP
Add the following to the .htaccess file:
<Limit GET>
order allow,deny
deny from 128.23.45.
deny from 207.158.255.213
allow from all
</Limit>
This is an example of a .htaccess file that will block access to your site to anyone who is coming from any IP address beginning with 128.23.45 and from the specific IP address 207.158.255.213 . By specifying only part of an IP address, and ending the partial IP address with a period, all sub-addresses coming from the specified IP address block will be blocked. You must use the IP addresses to block access, use of domain names is not supported. To deny all IP addresses from your site use:
<Limit GET>
order allow,deny
deny from all
</Limit>Change your default directory page
Some of you may be wondering what is DirectoryIndex? It is a command which allows you to specify a file that is to be loaded as your default page whenever a directory or url request comes in, that does not specify a specific page.
DirectoryIndex filename.html
This would cause filename.html to be treated as your default page, or default directory page. You can also append other filenames to it. You may want to have certain directories use a script as a default page.
DirectoryIndex filename.html index.cgi index.pl default.htm
Placing the above command in your htaccess file will cause this to happen:
When a user types in yoursite.com, your site will look for filename.html in your root directory (or any directory if you specify this in the global htaccess), and if it finds it, it will load that page as the default page. If it does not find filename.html, it will then look for index.cgi; if it finds that one, it will load it, if not, it will look for index.pl and the whole process repeats until it finds a file it can use. Basically, the list of files is read from left to right.Prevent viewing of .htaccess file
If you use htaccess for password protection, then the location containing all of your password information is plainly available through the htaccess file. If you have set incorrect permissions or if your server is not as secure as it could be, a browser has the potential to view an htaccess file through a standard web interface and thus compromise your site/server. This, of course, would be a bad thing. However, it is possible to prevent an htaccess file from being viewed in this manner:
<FILES .htaccess>
order allow,deny
deny from all
</FILES>
The first line specifies that the file named .htaccess is having this rule applied to it. You could use this for other purposes as well if you get creative enough. If you use this in your htaccess file, a person trying to see that file would get returned (under most server configurations) a 403 error code. You can also set permissions for your htaccess file via CHMOD, which would also prevent this from happening, as an added measure of security: 644 or RW-R--R--Redirects
Ever go through the nightmare of changing significantly portions of your site, then having to deal with the problem of people finding their way from the old pages to the new? There are different ways of redirecting pages, through http-equiv, javascript or any of the server-side languages. You can do it through htaccess, which is probably the most effective, considering the minimal amount of work required to do it.
Htaccess uses redirect to look for any request for a specific page and if it finds that request, it forwards it to a new page you have specified:
Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html
Note that there are 3 parts to that, which should all be on one line.
The redirect command.
The location of the file/directory you want redirected relative to the root of your site (/olddirectory/oldfile.html = yoursite.com/olddirectory/oldfile.html)
The full URL of the location you want that request sent to.
Each of the 3 is separated by a single space, but all on one line. You can also redirect an entire directory by simple using:
Redirect /olddirectory/ http://yoursite.com/newdirectory/
Using this method, you can redirect any number of pages no matter what you do to your directory structure. It is the fastest method as a global affect.Adding MIME Types
What are MIME Types?
MIME stands for Multipurpose Internet Mail Extensions. It extends the power of web browsers to handle graphics, sound and multimedia. MIME is also used for binary email attachments. Browsers recognize MIME types in categories and file types, separated by a slash (such as image/gif). If you've registered a MIME type, the browser decodes the file and launches a helper application. What if your server wasn't set up to deliver certain file types properly? A common occurrence with MP3 or even SWF files. Simple enough to fix with htaccess:
To do this you must first understand the three parts of adding a MIMI type. The first part is the AddType. This tells the server that you are adding a MIME type. Second is the application string. This is the actual parameter of the MIME you are adding (the MIME type). The final part is the default extension for the MIME type you want to add.
AddType mime-type .ext
Save the .htaccess file and store all ext files in the same directory. Then, all files in the directory that end in .ext (those extensions you have added) will be mapped into mime-type and handled properly by the server. Please note that you must include a period (.) before the extension. You can list several extensions separated by blanks. For example, if you wanted to store and serve Lotus 1-2-3 files with the extensions wks, wk1, wk2, wk3, and wk4, you should type:
AddType application/lotus123 .wks .wk1 .wk2 .wk3 .wk4
By the way, here's a neat little trick that few know about. To force a file to be downloaded, via the Save As browser feature, you can simply set a MIME type to application/octet-stream and that immediately prompts you for the download.Preventing hot linking of images
In the webmaster community, "hot linking" is a curse phrase. Also known as "bandwidth stealing". It refers to linking directly to non-html objects not on one own's server, such as images, .js files etc. The victim's server in this case is robbed of bandwidth (and in turn money) as the violator enjoys showing content without having to pay for its deliverance. The most common practice of hot linking pertains to another site's images.
In the webmaster community, "hot linking" is a curse phrase. Also known as "bandwidth stealing". It refers to linking directly to non-html objects not on one own's server, such as images, .js files etc. The victim's server in this case is robbed of bandwidth (and in turn money) as the violator enjoys showing content without having to pay for its deliverance. The most common practice of hot linking pertains to another site's images.
The best way to stop hot linking is to have your images be placed in a seperate folder (not the same folder as html files) and put a .htaccess file in it.
Copy this text below, make the changes to show your domain info, and paste it into notepad. Name this file .htaccess and place in in all your images folders. Be sure to upload in ASCII mode or the .htaccess file will not work.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Be sure to replace "mydomain.com" with your own. The above code causes a broken image to be displayed when its hot linked. You can have an image display for those who try to hot link. You can have an image of your choice be displayed for those attempting to steal bandwidth. The code for this is:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/notallowed.gif [R,L]
The first line tells Apache to turn on the MOD Rewite.
The next two lines you change to your address (either with, and without the www. as well as your IP).
The last line is where you would like the link from the site trying to download from their pages to be redirected. This way if some one links directly to your "coolpicture.jpg" from their website, instead of seeing your cool picture the user will see a picture that you decide to show. Make the picture be something the user will not want to see and get the message across that he is a bandwidth stealer. After the user sees that the "hot linking" isn't working, the user will change his links.
In order to have it work for you:
replace mydomain.com with your own domain
replace the notallowed.gif with the image you want them to see.
Hacking Minesweeper
With your cursor inside the minesweeper window type “XYZZY” (CASE SENSITIVE) then press Shift-Enter and Enter. A white dot should appear in the upper-left corner of the screen. If it turns black, your cursor is resting on a mine. If it is white, you are safe to click. This works best if you set your background image to ‘none’ and your background color to black. It doesn’t work on Win 95 or NT, but who gives a shit.
Hacking Freecell
While playing, hold Ctrl-Shift-F10. You will be asked if you want to Abort, Retry or Ignore. Choose ABORT, then move any card and you’ll win immediately. Pretty cool, eh? Enjoy pissing off your friends by making them a bet that you can win any game of Freecell in 1 move.
Hacking Pinball on Windows XP
Start a new game, then type “hidden test”. Nothing happened, right? Okay smart guy, go ahead and put your mouse over the Pinball window, click, and drag. Yeah, the ball is following the mouse, I know. Try pressing ‘R’. Yep, your rank just went up. Now press ‘H’. Uhuh, you just got to enter yourself on the high score list with 1,000,000,000 points.
Solitaire Cheat
Cheats
Draw single cards in a Draw Three game
Everytime you flip the top stack of cards, hold down CTRL-ALT-SHIFT and instead of flipping three card you only flip one card. This way you can draw single cards but still have the higher score of a ”Draw Three” game.
Codes
Force Victory
This code should be entered during a normal game.
Alt+Shift+2
Glitches
Infinite Points
In the Windows XP version of solitaire, draw from the deck at least twice. Hold control and drag a card down from the deck. Click the “A” key and then let go of the left mouse key. You will get 10 points for this. Continue doing this for infinite points!
Infinite points
To do this trick, finish a game of solitaire with the time bonus option on. The cards will start bouncing. Click on the solitaire screen and the play again box will pop up. Select no, so the solitaire screen is just blank green. Use the instant win cheat (Alt+Shift+2) and you will recieve the time bonus you got last game will be added to your last game’s score. For example, if your time bonus was 5000, and your final score was 6000, after using this glitch, you will have a score of 11000. This glitch can be used as many times as you want.
Move a card to an illegal position
Use the left mouse button and drag a card onto any legal position, just as you normally would, but do not let go of the left mouse button. While holding the card over the position, hit the Escape key once, then release the left mouse button. Now left click once on any face-up card at all and it will teleport to that position. You may also use the space bar and directional arrows to do this, however the final click to teleport the card must still be done with the left mouse button.
Well, that’s all folks.
Monday, May 21, 2007
How do I return row numbers with my query?
Lastname Firstname
-------- ---------
Evans Bob
Smith Frank
And they would want this:
Rownum Lastname Firstname
------ -------- ---------
1 Evans Bob
2 Smith Frank
This would act like Oracle's ROWNUM, which isn't supported in SQL Server.
Of course, once you've retrieved this resultset into your ASP page, you could use a counter to increment as you're processing. This is by the easiest way, e.g.
<%
' ...
set rs = conn.execute(sql)
counter = 0
do while not rs.eof
counter = counter + 1
response.write counter & " "
response.write rs(0) & "
"
rs.movenext
loop
' ...
%>
However, some people really, really, really want the row number to come back from the database. It's a little less efficient, but let's examine a few methods. Given this sample data:
SET NOCOUNT ON
CREATE TABLE people
(
firstName VARCHAR(32),
lastName VARCHAR(32)
)
GO
INSERT people VALUES('Aaron', 'Bertrand')
INSERT people VALUES('Andy', 'Roddick')
INSERT people VALUES('Steve', 'Yzerman')
INSERT people VALUES('Steve', 'Vai')
INSERT people VALUES('Joe', 'Schmoe')
The first method we'll try is a COUNT with a GROUP BY:
SELECT
rank = COUNT(*),
a.firstName,
a.lastName
FROM
people a
INNER JOIN people b
ON
a.lastname > b.lastname
OR
(
a.lastName = b.lastName
AND
a.firstName >= b.firstName
)
GROUP BY
a.firstName,
a.lastName
ORDER BY
rank
We can also try a COUNT as a subquery, which doesn't require GROUP BY (which means you could include other columns in the outer query).
SELECT
rank = (
SELECT COUNT(*)
FROM people b
WHERE
a.lastname > b.lastname
OR
(
a.lastName = b.lastName
AND a.firstName >= b.firstName
)
),
a.firstName,
a.lastName
FROM
people a
ORDER BY
a.firstName,
a.lastName
Results in all cases:
rank firstName lastName
---- --------- --------
1 Aaron Bertrand
2 Andy Roddick
3 Joe Schmoe
4 Steve Vai
5 Steve Yzerman
Note that if you have duplicates in your table, you will end up with something like this:
1 Aaron Bertrand
3 Joe Schmoe
3 Joe Schmoe
So, to avoid this, you might want to make sure that either (a) you avoid and remove duplicates (see Article #2431); or (b) if duplicates are allowed and make sense for your data model, that you have some other primary key or unique identifier. Then, you can make it a part of the query; for example:
SET NOCOUNT ON
CREATE TABLE people
(
peopleID INT IDENTITY(1,1) PRIMARY KEY,
firstName VARCHAR(32),
lastName VARCHAR(32)
)
GO
INSERT people VALUES('Aaron', 'Bertrand')
INSERT people VALUES('Andy', 'Roddick')
INSERT people VALUES('Steve', 'Yzerman')
INSERT people VALUES('Steve', 'Yzerman')
INSERT people VALUES('Steve', 'Vai')
INSERT people VALUES('Joe', 'Schmoe')
SELECT
rank = (
SELECT COUNT(*)
FROM people b
WHERE a.lastName > b.lastName
OR
(
a.lastname = b.lastname
AND a.firstName >= b.firstName
)
) - (
SELECT COUNT(*) FROM
people b
WHERE a.lastName = b.lastName
AND a.firstName = b.firstName
AND a.peopleID < b.peopleID
),
a.firstName,
a.lastName
FROM
people a
ORDER BY
a.lastName,
a.firstName
Results:
rank firstName lastName
---- --------- --------
1 Aaron Bertrand
2 Andy Roddick
3 Joe Schmoe
4 Steve Vai
5 Steve Yzerman
6 Steve Yzerman
Grouping within groups
Often, you'll want a more complex row number scheme, for example you might want to rank within groups of a hierarchy. Let's say we wanted to list sports teams, and assign "ranks" alphabetically, within each city:
CREATE TABLE #teams
(
city VARCHAR(20),
team VARCHAR(20)
)
SET NOCOUNT ON
INSERT #teams SELECT 'Boston', 'Celtics'
INSERT #teams SELECT 'Boston', 'Bruins'
INSERT #teams SELECT 'Boston', 'Red Sox'
INSERT #teams SELECT 'New York', 'Yankees'
INSERT #teams SELECT 'New York', 'Mets'
INSERT #teams SELECT 'New York', 'Knicks'
INSERT #teams SELECT 'New York', 'Rangers'
INSERT #teams SELECT 'New York', 'Islanders'
INSERT #teams SELECT 'New York', 'Jets'
INSERT #teams SELECT 'New York', 'Giants'
INSERT #teams SELECT 'Chicago', 'Black Hawks'
INSERT #teams SELECT 'Chicago', 'Cubs'
INSERT #teams SELECT 'Chicago', 'White Sox'
INSERT #teams SELECT 'Chicago', 'Bears'
INSERT #teams SELECT 'New England', 'Patriots'
SELECT city, team, rank =
(
SELECT COUNT(*)
FROM #teams t2
WHERE t2.city = t1.city
AND t2.team <= t1.team
)
FROM #teams t1
ORDER BY city, team
DROP TABLE #teams
Results:
city team rank
------------ ------------ ----
Boston Bruins 1
Boston Celtics 2
Boston Red Sox 3
Chicago Bears 1
Chicago Black Hawks 2
Chicago Cubs 3
Chicago White Sox 4
New England Patriots 1
New York Giants 1
New York Islanders 2
New York Jets 3
New York Knicks 4
New York Mets 5
New York Rangers 6
New York Yankees 7
Keep in mind that, since your presentation tool (Crystal Reports, ASP, PHP, what have you) is going to have to treat every row separately anyway, it makes sense to just retrieve the rows in the correct order, and let the application compare every row to see if this is a new city or not, and accordingly increment the count or start over. This will greatly reduce the amount of strain you're putting on the database.
Just curious.
Too funny to miss...sadly kinnda true
Could this be Nolan Curtis' long lost brother?
From: George Wiman
Sent: Monday, April 21, 2003 1:12 PM
To: submissions@bbspot.com
Subject: Profanity and computers
I know the popular theory is that high-tech devices run on electricity. But that theory is wrong: high-tech devices run on profanity. When was the last time you swore at a lamp? Lamps run on electricity, not profanity. Computers have several small lamps in them, which is why they need some electricity, but swearing at a computer really does make it run better.
- -
Having been in the computer support field for eight years, I feel qualified to make this statement. People think I'm a technical guru but my secret is constantly muttering profanity under my breath while I fix their systems. It's easy - anyone can learn to do it.
- -
As an example, this weekend, I needed to run a network cable from the router in my basement to my workbench. My terminal crimper was broken, so I set out to buy a new one. Swearing dutifully at traffic on the way, I arrived safely to purchase the replacement crimper and some CAT5 certified RJ45 cable ends.
- -
CAT5e cable is expensive, but I didn't have to buy any thanks to the wastefulness of several construction projects around town (an ample supply can be found in dumpsters.) I selected a long piece from my box of salvaged cable and arranged the twisted wires for crimping. Since I am quite dyslexic, I got the order wrong, resulting in a nonfunctional cable and nearly an hour's troubleshooting with network properties on the computer. What happened?
- -
Well, I remembered to swear at the computer, so the network properties were set correctly. Wait! I forgot to cuss out the cable! Sure enough, I had calmly and confidently set the wires into the terminals and crimped them, without comparing them to excrement or questioning if the wire was excessively attached to its mother. The cable could not work.
- -
Correcting that error, I cut off the incorrectly made terminals. I again consulted the cable chart, cursing the design of the chart that had mislead my dyslexic vision, the maker of the crimping tool, and the manufacturer of the wire for making the color-coding too hard to see. (Never mind that my eyesight isn't what it used to be.) Need I add that the cable now worked perfectly?
- -
A technician friend of mine says that high-tech devices run on smoke, not profanity. He says that everything works fine until a malfunction lets the smoke out, and after that the device doesn't work anymore. He could be right, though I notice he liberally applies an astounding range of obscenity while fixing systems. He is a master technician, covering all the bases.
- -
Mark Twain said that he "...found in profanity solace unexcelled by prayer." People who object to 'bad' words as an affront to morality need to stop and give thanks for everything the high-tech revolution has given them. All over the world, tech people are swearing, cussing, inventing new obscene suggestions for Bill Gates, just to keep the world's technology working. It's not just a job, it's a calling.
George Wiman, Computer Support Specialist
Wednesday, May 16, 2007
How do I cast a string to an int, float, double, etc?
You can use the Convert class or the Parse method of the built-in type you are casting to. i.e.
string myStr = "123";
int myParsedInt = Int32.Parse(myStr);
int myConvertedInt = Convert.ToInt32(myStr);
This example uses the int type, but you can also use the same techniques for any of the other integral or floating point types.
OPen Source...it aint as bad
Say at the stroke of midnight, all open source software magically vanished. What would still work tomorrow?
For starters, the Internet would “disappear” for the average user. Most Domain Name Servers (DNS) are run on open source software like BIND, which turns www.whurley.com into the IP address of the appropriate server. The majority of basic Internet users would be literally lost in translation. Of course, BIND isn't the only open source software for DNS. And not all DNS solutions are open source.
So assume DNS still works or perhaps you memorized 72.14.207.99 instead of www.google.com. Even with name servers functioning, Google would drop off of the face of the Internet. Google is primarily powered by Linux—arguably the most popular open source operating system on the planet. No worries. You'll just pop over to Yahoo!, right? Wrong. Yahoo! is one of the largest consumers of another popular open source operating system: FreeBSD. Now you’ve resigned yourself to trying 207.68.172.246. We all know they're not running open source, and they've been working hard on that search feature for quite some time.
Ok, MSN is up and running, now execute a search. I heard a sweet Shakira remix on the radio this morning; I’m going to search for that. MSN returns a list of sites offering the song . . . I’m clicking on them . . . and . . . nothing. No dancing? No Latin rhythms? Over 60% of all Internet sites are powered by Apache, an open source web server. Before I even click on a link, my chances of success have been reduced to 4 in 10.
Of the 118,023,363 sites surveyed by NetCraft so far in the month of May, just over 70 million of them wouldn't work if open source software were to disappear. Of course, Apache isn't the only open source web server and . . . you know the rest. I could go on and on about how none of your online transactions would be secure without OpenSSH and OpenSSl and all the other services users access every day that wouldn’t exist in this scenario.
Open source is not a new trend. It’s not a fad. It’s everywhere, whether you recognize it or not. From the embedded Linux in new wireless routers to Firefox, the world's most popular open source browser, open source powers the Internet and countless other technologies.
You already know I’m a true believer, but what do you all think? I’d like to hear your thoughts on how the disappearance of open source would affect you.
Installing Apache PHP and MySQL
PHP and MySQL are usually associated with LAMP (Linux, Apache, MySQL, PHP).
However, most PHP developer ( including me ) are actually using Windows when
developing the PHP application. So this page will only cover the WAMP ( Windows,
Apache, MySQL, PHP ). You will learn how to install Apache, PHP, and MySQL
under Windows platform.
The first step is to download the packages :
- Apache : www.apache.org
- PHP : www.php.net
- MySQL : www.mysql.com
You should get the latest version of each packages. As for the example in
this tutorial i'm using Apache 2.0.50 ( apache_2.0.50-win32-x86-no_ssl.msi
), PHP 4.3.10 ( php-4.3.10-Win32.zip ) and MySQL 4.0.18 ( mysql-4.0.18-win.zip
).
Now let's start the installation process one by one.
- Installing Apache
- Installing PHP
- Modifying Apache Configuration
- Installing MySQL
- Modifying PHP Configuration File
Installing ApacheInstalling apache is easy if you download the Microsoft Installer ( .msi I'm using Windows XP and installed Apache as Service so everytime I start Click the Next button and choose Typical installation. Click Next one more To see if you Apache installation was successful open up you browser and
By default Apache's document root is set to htdocs For example, if you want to put all your PHP or HTML files in C:\www DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs" and change it to : DocumentRoot "C:/www" After making changes to the configuration file you have to restart Apache Another configuration you may want to change is the directory index. Suppose you want apache to use index.html, index.php DirectoryIndex index.html index.php main.php Now whenever you request a directory such as http://localhost/ |
Installing PHPFirst, extract the PHP package ( php-4.3.10-Win32.zip ). I extracted the Next, move the php4ts.dll file from the newly created php directory into
Side Note : Thanks to Shannon Tang for pointing this out |
Modifying Apache ConfigurationApache doesn't know that you just install PHP. We need to tell Apache about LoadModule php4_module php/sapi/php4apache2.dll The first line tells Apache where to load the dll required to execute PHP Now restart Apache for the changes to take effect ( Start <?php phpinfo(); ?> phpinfo() is the infamous PHP function which
|
Installing MySQLFirst extract the package ( mysql-4.0.18-win.zip ) to a temporary directory, Open a DOS window and go to C:\mysql\bin and C:\mysql\bin>mysqld-nt --console InnoDB: The first specified data file .\ibdata1 did not exist: InnoDB: a new database to be created! 040807 10:54:09 InnoDB: Setting file .\ibdata1 size to 10 MB InnoDB: Database physically writes the file full: wait... 040807 10:54:11 InnoDB: Log file .\ib_logfile0 did not exist: new to be created InnoDB: Setting log file .\ib_logfile0 size to 5 MB InnoDB: Setting log file .\ib_logfile1 size to 5 MB Now open another DOS window and type C:\mysql\bin\mysql if your installation is successful you will see the MySQL client running C:\mysql\bin>mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 4.0.18-nt Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> Type exit on the mysql> prompt to quit the MySQL client. Now let's install MySQL as a Service. The process is simple C:\mysql\bin>mysqladmin -u root shutdown C:\mysql\bin>mysqld-nt --install C:\mysql\bin>net start mysql The MySQL service was started successfully.
Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> |
Modifying PHP Configuration File ( php.ini )PHP stores all kinds of configuration in a file called php.ini.You Some of the configurations are :
register_globalsBefore PHP 4.2.0 the default value for this configuration is On error_reporting and display_errorsSet the value to error_reporting = E_ALL during The reason to use E_ALL during development is so you can catch most of However, after production you should change the value to E_NONE so PHP One important thing to note is that you will also need to set the value extension and extension_pathPHP4 comes with about 51 extensions such as GD library ( for graphics creation The value of extension_path must be set to Don't forget to add that last slash or it won't work After specifying the extension_path you will session.save_pathThis configuration tells PHP where to save the session data. You will need max_execution_timeThe default value for max_execution_time is If you think your script will need extra time to finish the job you can PHP have a convenient function to modify PHP configuration in runtime, |
Wednesday, May 9, 2007
Converting C# month from int to Name
DateTime.Parse("01-JAN-1970").AddMonths(intMonth ).ToString("MMMM")
Handy tip
This assumes that intMonth is zero-based. Otherwise, use intMonth - 1. If you're doing it repeatedly, you want to store the results of DateTime.Parse(), natch.
Selecting concatanation fo two columns in SQL
But, what when you want to select three numbers concatanated...namely, month, date and year...
try using "+" and the SQL server gives you the sum of the three numbers which is no good...
Here is a tiny trick i played on SQL server...
SELECT (Upper(MONTH)) + '/'+Upper(Day)+'/' +Upper(Year) as Date FROM DateTable...
when the SQL server does toUpper function, it assumes, the argument is a string and volah..the query runs seemlessly
Have fun coding...
Thursday, May 3, 2007
Dropdown calendar for C#
<h2> IAI Calendar</h2> <br /> <div style="width:100%;">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"
AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList> <br /> <asp:Label ID="Label1" runat="server"></asp:Label><br
/> </div>
backend
protected void Page_Load(object sender, EventArgs e) { DateTime tnow = DateTime.Now;
ArrayList AlYear = new ArrayList(); int i; for (i = 2002; i <= 2010; i++) AlYear.Add(i);
DateTime month = Convert.ToDateTime("1/1/2000"); for(i=0;i<12;i++) { DateTime
NextMont = month.AddMonths(i); ListItem list = new ListItem(); list.Text = NextMont.ToString("MMMM");
list.Value = NextMont.Month.ToString(); DropDownList2.Items.Add(list); } if (!IsPostBack)
{ DropDownList1.DataSource = AlYear; DropDownList1.DataBind(); DropDownList1.SelectedValue
= tnow.Year.ToString(); DropDownList2.SelectedValue = tnow.Month.ToString(); } Label1.Text
= "You select date:" + DropDownList1.SelectedValue + "year" + DropDownList2.SelectedValue
+ "month" ; } public void DropDownList1_SelectedIndexChanged(object sender, EventArgs
e) { } public void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{ }
Monday, April 30, 2007
Shayari
zamii.n par banaayaa na ghar zindagii bhar
sabhii log jiine kaa fan jaanate hai.n
na aayaa hame.n ye hunar zindagii bhar
mohabbat rahii chaar din zindagii me.n
rahaa chaar din kaa asar zindagii bhar
har taraf har jagah beshumaar aadamii
phir bhii tanahaaiiyo.n kaa shikaar aadamii
subah se shaam tak bojh Dhotaa huaa
apanii hii laash kaa Khud mazaar aadamii
har taraf bhaagate dauDate raaste
har taraf aadamii kaa shikaar aadamii
roz jiitaa huaa roz marataa huaa
har nae din nayaa intazaar aadamii
zindagii kaa muqaddar safar dar safar
aaKhirii saa.Ns tak beqaraar aadamii
Lyrics of Meri Kahani
tumhe kaise bhula sakta hoon,
kaise dil se mita sakta hoon
meri saanson ka hissa ho tum
meri kahani mera kissa ho tum (2)
tumhe kaise bhula sakta hoon,
kaise dil se mita sakta hoon
meri saanson ka hissa ho tum....meri kahani
Hum pyaar ki daur se, bandhe bhi hue hain, toote bhi hue hain (2)
Aur haath se haath yeh, mile bhi hue hain, choote bhi hue hain
Hum saath hain par humsafar nahi,
mere pass nahi toh door sahi,
par meri toh manzil ho tum
meri kahani mera kissa ho tum
tumhe kaise bhula sakta hoon,
kaise dil se mita sakta hoon
meri saanson ka hissa ho tum..meri kahani
Har khushi saath thi, mere tum the magar
ek pal mein tumhe kho diya
dooriyaan chaa gayi, jaise baadal koi aasmaan main phir ro diya
Hum door hue the jaane kyun (2)
ab pass hai toh lagta hai yun, ki ek pal ka, sapna ho tum
meri kahani mera kissa ho tum (2)
tumhe kaise bhula sakta hoon,
kaise dil se mita sakta hoon
meri saanson ka hissa ho tum
meri kahani...meri kahani
Friday, April 27, 2007
OMG check this out
So, if you can get hands on a windows machine for 3-5 minutes, you can practically have the passwords...
http://ophcrack.sourceforge.net/
Thursday, April 26, 2007
Identity reset for SQL Server 2000
It usually takes me around 2 mins to delete the data and reset the identity..
Here is a handy script which would actually reset the seed back to 0
Delete FROM tableName;
DBCC CHECKIDENT('tabelName', RESEED, 0)
Be careful though when working with foreignkeys...
I usually drop all relationships while am testing a perticular table and once the data insertion part makes me happy, I put the relations back and test again...
makes deletions and resets eazier...
Zeehal E Maskin Mukun baranjish
ba-ranjish..." written by Gulzar from the movie Ghulami. I got this
information from a discussion among some Gulzar fans on Orkut.
There is a wonderful remark after the song.
First the meaning of the mukhda:
---------------------------------
zihaal-e-miskeen mukon ba-ranjish, bahaal-e-hijra bechara dil hai
zihaal = notice
miskeen = poor
mukon = do not
ba-ranjish = with ill will, with enimity
bahaal = fresh, recent
hijra = separation
Thus the meaning is: Notice the poor (heart), and do not look at it (heart)
with enimity. It (heart) is fresh with the wounds of separation.
Hindi mein (and more clearly): Ye dil judaai ke gamo se abhi bhi taaza hai.
Iski bechaargi ko ba-ranjish (without enimity) dekho.
Now the full song (it's really beautiful).
---------------------------------------------
(There is equally beautiful remark after the song)
zihaal-e-miskeen mukon ba-ranjish
bahaal-e-hijra bechara dil hai
sunaai deti hai jisaki dhaDakan
tumhaaraa dil ya hamaaraa dil hai
vo aake pahaloo meiN aise baiThe
ke shaam raNgeen ho gayi hai
zaraa zaraa si khili tabeeyat
zaraa si gamgeen ho gayi hai
kabhi kabhi shaam aise Dhalatee hai
jaise ghooNghaT utar rahaa hai
tumhaare seene se uThta dhuaaN
hamaare dil se guzar raha hai
ye sharm hai ya hayaa hai kya hai
najar uThaate hi jhuk gayi hai
tumhaari palakoN se girke shabanam
hamaari aaNkhoN meiN ruk gayi hai
Now a remark
--------------
Many words of this song are in Persian. The phrase "Zihaal-e-miskeen"
comes from a poem of Amir Khusrau. This original poem of Amir Khusrau
is a unique masterpiece. The beautiful thing about this poem is that
it it written in Persian and Brij bhasha simultaneously. The first
line is in Persian, second in Brij bhasha, third in persian, and so
on...!! What an unbelievable talent. And here are first four lines of
that poem.
zihaal-e-miskeen mukon taghaful (Persian)
doraaye nainaan banaye batyaan (Brij)
ke taab-e-hijraah nadarum-e-jaan (Persian)
na laihyo kaahe lagaye chatyaan (Brij)
This showcases Hazrat Amir Khusrau's mastery over the two languages and the
role played by him in the genesis of Urdu.
The complete poem taken from http://www.alif-india.com/ is
Ziehal-e miskeenn makun taghaful, duraye naina banaye batiyan;
ki taab-e hijran nadaram ay jaan, na leho kaahe lagaye chhatiyan.
Shaban-e hijran daraz chun zulf wa roz-e waslat cho umr kotah;
Sakhi piya ko jo main na dekhun to kaise kaatun andheri ratiyan.
Yakayak az dil do chashm-e jadoo basad farebam baburd taskin;
Kise pari hai jo jaa sunaave piyare pi ko hamaari batiyan.
Cho shama sozan cho zarra hairan hamesha giryan be ishq aan meh;
Na neend naina na ang chaina na aap aaven na bhejen patiyan.
Bahaqq-e roz-e wisal-e dilbar ki daad mara ghareeb Khusrau;
Sapet man ke waraaye raakhun jo jaaye paaon piya ke khatiyan.
And the English translation is:
Do not overlook my misery by blandishing your eyes,
and weaving tales; My patience has over-brimmed,
O sweetheart, why do you not take me to your bosom.
Long like curls in the night of separation,
short like life on the day of our union;
My dear, how will I pass the dark dungeon night
without your face before.
Suddenly, using a thousand tricks, the enchanting eyes robbed me
of my tranquil mind;
Who would care to go and report this matter to my darling?
Tossed and bewildered, like a flickering candle,
I roam about in the fire of love;
Sleepless eyes, restless body,
neither comes she, nor any message.
In honour of the day I meet my beloved
who has lured me so long, O Khusrau;
I shall keep my heart suppressed,
if ever I get a chance to get to her trick.