Free Code Collection

Tag: WEB DESIGN

Avoid automatically post form via CAPTCHA

by Hussain on Jul.26, 2009, under PHP

A good way to avoid automatic form submissions when creating a web form is to add some kind of verification. One of the best ways is to use an image verification, called also captcha. What it does is to dynamically create an image with a random string displayed on it. Then visitor is asked to type that string in a text field and once the form is submitted it checks if the string on the image matches the one inputted by the user. Because there is no easy way to read a text from an image (image recognition) this is a good way to protect your web forms from spammers.
For doing this CAPTCHA I would suggest using a session variable where you store the string generated and displayed on that dynamically generated image.
 MySQL |  copy code |? 
1
CREATE TABLE `comment` (
2
`name` varchar(50) collate latin1_general_ci NOT NULL,
3
`mail` varchar(50) collate latin1_general_ci NOT NULL,
4
`url` varchar(50) collate latin1_general_ci NOT NULL,
5
`comment` longtext collate latin1_general_ci NOT NULL
6
)
Create a page comment.php and create form for post comments:
 HTML |  copy code |? 
01
<form name=”commentform” action=”comments-post.php” method=”post” id=”commentform”>
02
<table width=468? border=0? cellspacing=3? cellpadding=3?>
03
<tr>
04
<td width=103?>Name</td>
05
<td width=344?><input name=nametype=textid=nametabindex=1? value=" size=”18? /></td>
06
</tr>
07
<tr>
08
<td>Mail</td>
09
<td><input type=textname=”email” id=”email” value=" size=”18? tabindex=”2? /></td>
10
</tr>
11
<tr>
12
<td>URL</td>
13
<td><input type=textname=”url” id=”url” value=" size=”18? tabindex=”3? /></td>
14
</tr>
15
<tr>
16
<td>Enter Number </td>
17
<td><input name=”txtNumber” type=textid=”txtNumber” value=" tabindex=”4?/>
18
<img src=”randImages.php”/></td>
19
</tr>
20
<tr>
21
<td>Comment</td>
22
<td><textarea name=”comment” id=”comment” cols=45? rows=9? tabindex=5?></textarea></td>
23
</tr>
24
<tr>
25
<td>&nbsp;</td>
26
<td><input name=”save” type=”submit” class=”submitbutton” id=”save” tabindex=5? onClick=”MM_validateForm(name’,”,’R',’email’,”,’RisEmail’,'comment’,”,’R');return document.MM_returnValue” value=”Submit Comment”/></td>
27
</tr>
28
</table>
29
</form>
Now we will create a Image Verification Page which will show Random Images, Save this page as randImages.php.
 PHP |  copy code |? 
01
session_start();
02
// $Rand Function generate 5 digit random number starting 10000, 99999. You can Edit it as your required.
03
$rand = rand(10000, 99999);
04
// create the hash for the random number and put it in the session
05
$_SESSION['image_random_value'] = md5($rand);
06
// create the image
07
$image = imagecreate(60, 30);
08
// use white as the background image
09
$bgColor = imagecolorallocate ($image, 255, 255, 255);
10
// the text color is black
11
$textColor = imagecolorallocate ($image, 0, 0, 0);
12
// write the random number
13
imagestring ($image, 5, 5, 8, $rand, $textColor);
14
// send several headers to make sure the image is not cached
15
// taken directly from the PHP Manual
16
// Date in the past
17
header(”Expires: Mon, 10 April 2008 05:00:00 GMT”);
18
// always modified
19
header(”Last-Modified:. gmdate(”D, d M Y H:i:s”) . ” GMT”);
20
// HTTP/1.1
21
header(”Cache-Control: no-store, no-cache, must-revalidate”);
22
header(”Cache-Control: post-check=0, pre-check=0?, false);
23
// HTTP/1.0
24
header(”Pragma: no-cache”);
25
// send the content type header so the image is displayed properly
26
header(’Content-type: image/jpeg’);
27
// send the image to the browser
28
imagejpeg($image);
29
// destroy the image to free up the memory
30
imagedestroy($image);
31
?>
32
Now Create a page which insert the comment data.
33
session_start();
34
//Enter here your php mysql connection details
35
if(isset($_POST['save'])){
36
$name=$_POST['name'];
37
$email=$_POST['email'];
38
$url=$_POST['url'];
39
$comment=$_POST['comment'];
40
}
41
$number = $_POST['txtNumber'];
42
if (md5($number) == $_SESSION['image_random_value']) {
43
$sql=”INSERT into comment(name, mail, url, comment) values($name,$email,$url,
44
$comment);
45
$result=mysql_query($sql) or die(’Can not Add Your Comment’);
46
echo “Your Comment have been added. Returning To Write Return page here. Please wait…”;
47
$_SESSION['image_random_value'] =;
48
}
49
} else {
50
echo ‘Sorry, wrong Image Varification Number. Please try again’;
51
}
52
?>
  • Share/Save/Bookmark
Leave a Comment :, , , , , more...

[jQuery] changing default thickbox behavior

by Hussain on Jul.05, 2009, under Developers, JQuery

To prevent closing by clicking on the overlay and remove the ‘close’ link
(better IMHO than just disabling it), remove line 38:
$("#TB_overlay").click(TB_remove);

remove the TB_closeWindow <div> from line 133:
$("#TB_window").append("<a href=” id=’TB_ImageOff’ title=’Close’><img
id=’TB_Image’ src=’"+url+"’ width=’"+imageWidth+"’ height=’"+imageHeight+"’
alt=’"+caption+"’/></a>" + "<div id=’TB_caption’>"+caption+"<div
id=’TB_secondLine’>" + imageCount + prev.html + next.html + "</div></div>");

remove line 135:
$("#TB_closeWindowButton").click(TB_remove);

remove the TB_closeAjaxWindow <div> from line 205:
$("#TB_window").append("<div id=’TB_title’><div
id=’TB_ajaxWindowTitle’>"+caption+"</div></div><iframe
frameborder=’0′
hspace=’0′ src=’"+urlNoQuery[0]+"’ id=’TB_iframeContent’
name=’TB_iframeContent’ style=’width:"+(ajaxContentW +
29)+"px;height:"+(ajaxContentH + 17)+"px;’ onload=’TB_showIframe()’>
</iframe>");

and 207:
$("#TB_window").append("<div id=’TB_title’><div
id=’TB_ajaxWindowTitle’>"+caption+"</div></div><div
id=’TB_ajaxContent’
style=’width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;’></div>");

remove line 210:
$("#TB_closeWindowButton").click(TB_remove);
and remove lines 258-259:
$("#TB_overlay").unbind("click");
$("#TB_closeWindowButton").unbind("click");


Thickbox also has a keydown handler so that if you push ‘escape’ it closes.
Remove lines 236-245 to prevent this:
document.onkeyup = function(e){
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
if(keycode == 27){ // close
TB_remove();
}
}


To add the ‘close’ functionality to something, do this:
$("#myTbCloseButton").click(TB_remove);

Source: (http://www.mail-archive.com/discuss@jquery.com/msg18856.html)
  • Share/Save/Bookmark
Leave a Comment :, , , , , , , , more...

What’s New in Firefox 3.5

by narendra on Jul.03, 2009, under Web browser



Firefox 3.5  is based on the Gecko 1.9.1 rendering platform, which has been under development for the past year. Firefox 3.5 offers many changes over the previous version, supporting new web technologies, improving performance and ease of use. Some of the notable features are:

  • Available in more than 70 languages. (Get your local version!)
  • Support for the HTML5 <video> and <audio> elements including native support for Ogg Theora encoded video and Vorbis encoded audio. (Try it here!)
  • Improved tools for controlling your private data, including a Private Browsing Mode.
  • Better web application performance using the new TraceMonkey JavaScript engine.
  • The ability to share your location with websites using Location Aware Browsing. (Try it here!)
  • Support for native JSON, and web worker threads.
  • Improvements to the Gecko layout engine, including speculative parsing for faster content rendering.
  • Support for new web technologies such as: downloadable fonts, CSS media queries, new transformations and properties, JavaScript query selectors, HTML5 local storage and offline application storage, <canvas> text, ICC profiles, and SVG transforms.
Developers can find out about all the changes and new features at the Mozilla Developer Center.
  • Share/Save/Bookmark
Leave a Comment :, , , more...

Top 10 Firefox 3.5 Features

by Hussain on Jul.03, 2009, under Web browser

Firefox 3.5 is a pretty substantial update to the popular open-source browser, and it’s just around the corner. See what features, fixes, and clever new tools are worth getting excited about in the next big release.

UPDATE: A previous version of this list had Taskfox, an integrated version of Ubiquity, included as a Firefox 3.5 feature. It’s still in the experimental phase, in fact, as readers pointed out, and we regret the confusion (and false optimism!). This new list includes an additional item, and the rankings have been shifted slightly.

1. Video superpowers with HTML 5



If you’re viewing a page coded in HTML 5 with video in an open-source format like Ogg Vorbis or Theora, Firefox 3.5 treats that video like it’s just part of the page, not a separate little island of Flash content. That means instant commenting on videos. It could also mean offering links from inside a tutorial video that offer more details on what’s being shown—soldering tips on an iPhone repair guide would be keen. In general, it’s just a promising step forward into a seamless melding of video and text on a future web.

2. Geo-location

If you type
post office
into a maps site, you probably don’t want the headquarters of the U.S. Post Office, or post office listings from two towns over. Integrated geo-location, powered by Google’s Wi-Fi triangulation and simple IP address information, looks to know roughly where you are and help you when you’re looking for something local. You can disable it if you’d like, but, realistically, signing on from any IP address reveals a bit about where you are anyways. If a good number of sites pick it up, geo-location could bring to the browser what a lot of people are already enjoying on their phone.

3. TraceMonkey JavaScript engine

Months ago, Mozilla said its still-in-development JavaScript engine, TraceMonkey, was “20 to 40 times” faster than the SpiderMonkey engine installed in Firefox 3. That hasn’t shown up in our speed tests, which themselves rely on a Mozilla-assembled testing suite, but JavaScript testing suites are often like drag races—they don’t really tell you what a browser runs like in a real daily sense, just pure timings. Even if TraceMonkey is ultimately outpaced by Chrome and/or Safari, its innovations push the whole browser market forward and give us all a bit less load time to complain about.

 

 

4. Color profiles that pop

Different cameras, monitors, and capture devices grab and set colors in different ways. On the web, most colors look the same, though, because they’re filtered and optimized for quick viewing in every browser. Firefox 3.5 introduces dynamic color profiles for each picture, meaning that whatever the graphic designer or photographer saw when they were doing their work, you’ll see it on their web page.

5. Private browsing mode

The snarky types (i.e. my editor) can call it “Porn Mode,” but this feature, already in a number of competing browsers, has uses beyond the prurient. Beyond obvious situations, like gift buying and sensitive research, logging onto a friend’s browser for a quick email check or bill pay is made a lot more secure if you can get to the private mode. Likewise, anonymizing some of your searches and cookie collection on your own machine isn’t a bad idea, and a private mode can do that too. You don’t need it all the time, but you might be glad it’s available.

 

6. Smarter session restore

What good is it to bring back all the tabs you just lost to a crash if the tab that brought everything down comes back too? Firefox’s developers took a cue from the users and turned the session restore feature into more of a crash recovery tool, allowing users to select which tabs should come back. If you don’t know who’s the culprit, here’s a hint: It’s probably the one with Flash on it.

 

 

 

7. Keyword AwesomeBar filters

Firefox 3’s AwesomeBar/address bar offers a speedy list of suggestions to complete whatever you’re typing. That’s great, but that list comes from your page history, bookmarks, and tags, and can be matched by URL or name, leaving some results almost uselessly cluttered. This gets fixed with special character filters in the next Firefox. Restrict a search by typing “life *” for just your bookmarks with the words “life” in them, or just your tagged “lh” items with “lh +”. Anything that really makes getting back to importantly web destinations quickly is a welcome upgrade.

8. Tab tearing


Google Chrome (Update: And Safari, as our readers note) somewhat stole the thunder out from under this feature, but it’s still a nice one: Grab a tab and drag it out a bit to create a new browser window from it. Drag windows into tabs again, and open any tab in a new window from the right-click menu, if clicking and dragging isn’t your style.

9. Forget this site

Tools like Private Browsing Modes and history wipers are good for what they do, but sometimes it would be great to have just one site wiped off your history—either because it’s hogging your quick address bar results, or because you’d rather your coworker be unaware of your workday LOLcat browsing. Firefox 3.5’s history browser offers a convenient “Forget this site” option, erasing your browser’s memory of particular domains. It doesn’t cover subdomains, and your network traffic and Flash memory would still hold some details, but it’s a handy tweak however you cut it.

 

 

10. Undo closed window

If you accidentally close a tab you’d meant to keep open, Firefox 3, at least through extensions like Tab Mix Plus, can bring it back. Update: To clarify, Firefox can resurrect closed tabs without Tab Mix Plus (just hit Ctrl+Shift+T, for example); the extension simply adds more fine-grained control. If you accidentally kill a separate window full of tabs, though, you’ve been pretty much out of luck. Firefox 3.5 implements a restore feature for both tabs and windows from the History menu, which would (hopefully) also restore any text you’ve typed into them.
  • Share/Save/Bookmark
Leave a Comment :, , , more...

Javascript Library: Lightbox, Greybox, and Thickbox of jQuery

by Hussain on Jun.08, 2009, under JQuery

The web continues to impress me when I stumble across things that are relatively simple, yet done in such an elegant manner I can’t help but notice. This was the case when I discovered the Javascript overlay techniques of Lightbox, Greybox, and Thickbox.

Lightbox
Lightbox provides functionality to overlay images (with effects) onto your website – without using Flash or other plugins. It is perfect for creating a beautiful image gallery, while still maintaining easy control over your images! Don’t take my word for it, see for yourself: Lightbox JS v2.0

Note: In the same session, I also found a ‘Lite’ version for anyone that wants the same functionality, but with less code (and presumably resources). It is called Litebox 1.0
Litebox is a modified version of Lightbox v2.0created with one thing in mind, size reduction. Litebox utilizes the 3kb javascript library moo.fx in association with prototype.lite, giving us the basic tools we need to make this work and you the ability to expand.

Greybox
Greybox provides functionality to overlay HTML pages on your website – it describes itself as a “A pop-up window that doesn’t suck”. Greybox is very useful for providing visitors with additional information, a ‘focus area’ to input data, etc.Here is a demo page that shows the functionality of Greybox. Again, the smooth screen effects that are NOT using flash. SEO and Maintenance are still preserved (Flash experts, don’t flame me).

Thickbox
Last but not least, we have Thickbox. Thickbox combines both Lightbox and Greybox functionality, and still remains light weight – less than 50KB! It was actually the creator’s blog that introduced me to all three examples (Thank you Cody Lindley). You can view the demo to see the Thickbox in action – and notice that it can display overlays for the following extensions: .jpg .jpeg .png .gif .html .htm .cfm .php .asp .aspx .jsp .jst .rb .txt. It also supports AJAX/AXAH calls!

thickbox1

thickbox1



*Note: Inexperienced Javascript users may still consider Lightbox over Thickbox since it has some nice effects that Thickbox does not (example: Previous/Next tabs & hot keys)
  • Share/Save/Bookmark
4 Comments :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives

All entries, chronologically...