331 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for veedeoo

The purpose of this class is to be able to create an html form with ease. This is inspired by the form helper in CodeIgniter. This can easily adapt to bootstrap or any css and jquery where id is required. To use this class, we need to include the class …

Web Development php
Member Avatar for veedeoo
3
764
Member Avatar for rafaelbelliard

This simple but extremely useful trick explains how to hande a radiobutton within an ASP.NET gridview, without having to fiddle around with the sometimes cumbersome beast that javascript is. To avoid postbacks, we'll be using ASP.NET AJAX's updatepanel. Basically, the logic is grabbing the sender (ie, the radiobutton checked), disabling …

Web Development asp.net
Member Avatar for h4ng4r18
1
591
Member Avatar for diafol

Hello All. Been playing around with some linked dropdowns. It seems to be a recurring theme here on DW, so I thought I'd offer this up as a possible solution or for discussion, to see how it could be improved. The premise for this set of linked dropdowns is that …

Member Avatar for diafol
5
991
Member Avatar for tekagami

**Introduction** Lets say you have a website with a mobile version and a desktop version. Pictures can be resized proportinally using css on either version. But not all html tags resize proportionally, for instance: iframes. **Javascript Function** includes: the *id* of the iframe, the *original width* and *original height* See …

Web Development html-css javascript
Member Avatar for Hicaro_1
4
861
Member Avatar for <M/>

This is a pretty darn simple snippet that I learned from a site (don't remember the name). This is just the working Javascript which i managed to "easily" replicate :P Hopefully this will be useful for you guys. Note, this won't graph anything unless you have the html/css (i didn't …

Web Development javascript
Member Avatar for <M/>
0
216
Member Avatar for veedeoo

Hello Everyone, I wrote this script way back in 2008 as Version1. However, I was forced to forget about this, because it was criticized by many developers with BS, MS, and "Seasoned PHP Developer" under their names. During those days, I couldn't stand up for my own reasons, because I …

Web Development php
Member Avatar for veedeoo
2
2K
Member Avatar for diafol

**// EDIT 2014-04-07 //** New version (1.0.3) posted at the [bottom](http://www.daniweb.com/web-development/php/code/476623/ajaxed-linked-dropdowns-select-fields-for-volatile-data#post2082327) Demo Page: http://demos.diafol.org/ajax-linked-dropdowns.php *********************************************** Hello All. Been playing around with more linked dropdowns (select form fields), following the code snippet posted for static-ish data [here](http://www.daniweb.com/web-development/php/code/475238/linked-dropdowns-select-fields-for-static-ish-data). The static-ish version is of limited use (or of no use!) if data in …

Member Avatar for diafol
3
1K
Member Avatar for carllagerfeld

This is a function that I wrote and have re-used many times. I share it with you DaniWebers to use, laud or destroy! In a nutshell, this takes a user's search box input phrase and generates a series of LIKE clauses for your SELECT statement. Looks like "col1 LIKE '%s_term1%' …

Web Development php seo
1
477
Member Avatar for Szabi Zsoldos

Raffle function to generate unique numbers for each player, related to the same table with a recursive aproach. I had to do a simple raffle system for a contest that I was working on and tried many things and the most simple and the most effective one to generate unique …

Web Development mysql php
Member Avatar for diafol
0
902
Member Avatar for coreyavis

This is a function I created to facilitate the sending of PHP emails. Just give it the name and email of who your sending it to, and your name and email. A subject and a message. These options are required. The type, cc and bcc options are optional. By default, …

Web Development email php
Member Avatar for Airshow
1
846
Member Avatar for pritaeas

A while ago I explained how you could tag articles (see [this thread](http://www.daniweb.com/web-development/php/threads/387961/php-code-to-show-related-posts-on-a-blog)). Now you get a full working example. This code and the SQL script is also available on GitHub. The attached MySQL dump needs to be imported into your database, and you must update the credentials in the …

Web Development mysql php
Member Avatar for aufche
2
910
Member Avatar for digital-ether

Searching the net I couldn't find a simple way of retrieving HTTP Request Headers and HTTP Request Body in a PHP Script. PECL extensions offer this but not a standard PHP install. So heres a simple class that will do it for you. Docs in my blog: [URL]http://fijiwebdesign.com/content/view/90/77/[/URL]

Web Development php
Member Avatar for veedeoo
0
11K
Member Avatar for Krstevski

Hello friends, this code/snippet is nothing special, just a simple rss reader class written in PHP. Many times in my projects I use this script to get an RSS feed from some website and now i decided to share with you. This script can be useful for your projects or …

Web Development php xml
Member Avatar for diafol
0
990
Member Avatar for jkon

Some weeks ago I posted this and I realized from the referrals that it may help to be as a code snippet. This is an example of getting products details from categories – subcategories using ajax call. I am fond of OOP and this is not , but I believe …

Web Development javascript php
Member Avatar for pritaeas
1
3K
Member Avatar for josverhoeff

Hi, I thought I'd share this with you. If you want all fields on a web form to be emptied of ther initial value (if any) on focus and filled again with the initial value on blur. Works with jquery.

Web Development javascript javascript-jquery
Member Avatar for JJenZz
0
249
Member Avatar for BenWard

I had to map a network drive with specific credentials in my PHP script and it kept falling over because I'd already navigated to the drive in windows explorer. This snippet will unmap a network drive using COM regardless of whether or not there is a drive letter associated with …

Web Development hard-drive microsoft php storage
0
619
Member Avatar for tekagami

Sometimes a css file wont load because of a slow connection or a conflict between scripts (or just any other reason). This specially problematic on mobile websites (looking at you IOS) where many standards are applied. So this little script will add a link tag to the head tag and …

Web Development html-css javascript
Member Avatar for tekagami
0
269
Member Avatar for pritaeas

The following snippet shows how you can use binding in your queries when using MySQLi. For starters, here's the table structure I've used: CREATE TABLE `mytable` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `dob` date DEFAULT NULL, `level` int(11) DEFAULT NULL, PRIMARY …

Web Development mysql php
Member Avatar for pritaeas
3
1K
Member Avatar for faysal.ishtiaq_1

This code snippet can be used to get the current time in 12 hour format using JS

Web Development javascript
0
2K
Member Avatar for msteudel

I was being really lazy and didn't want to write one up myself, couldn't find one, and ended writing one up myself anyways. Hope this helps other lazy people.

Web Development php
Member Avatar for prafful_panwar
1
3K
Member Avatar for Coyx

Hi all, First tutorial submission. The standardised strtotime() function really grinds my gears. I hate messing about with dates in different formats... so I mullered this little function up. It works perfectly - probably easier ways to do it, I don't know... I just include this function in my functions …

Web Development php
Member Avatar for diafol
1
245
Member Avatar for kenleycapps

Ever feel the default session handling is insecure? Or do you just want some originality to show off? Well, here you are. A custom, MySQL-based session handler. It supports base64_encoding and MySQL storage. Note: I haven't tested this thing in months so I don't know how well it'll work : …

Web Development php
Member Avatar for pritaeas
0
456
Member Avatar for leokuz

For some reasone everytime I enter either correct mine or someone else's valid email and password, I get message: Sorry, your credentials are not valid, Please try again. What is wrong with this form?

Web Development php
Member Avatar for tpunt
0
410
Member Avatar for pritaeas

The following snippet shows how you can use binding in your queries when using PDO. For starters, here's the table structure I've used: CREATE TABLE `mytable` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `dob` date DEFAULT NULL, `level` int(11) DEFAULT NULL, PRIMARY …

Web Development php
3
1K
Member Avatar for vishalrane

[CODE]<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckCode.aspx.cs" Inherits="CheckCode" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Verification code to prevent auto signup in ASP.NET 2.0</title> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } a:link { color: #0000FF; } a:visited { …

Web Development asp.net
Member Avatar for yusuf_3
1
775
Member Avatar for pritaeas

The following code snippet shows how you can parse a DSN (Data Source Name). Why is it useful? You can now pass a single DSN parameter to your database wrapper class' constructor (instead of five separate parameters), and tear it apart into the components you need. The password and port …

Web Development php regex
1
1K
Member Avatar for Larrywaz

This piece of Java works perfectly so that onmouseover of the text an image is placed above the text, my problem is I can't come up with a piece of code for onmouseout to remove the image and restore the site to the way it was before the onmouseover. Right …

Web Development javascript
Member Avatar for Larrywaz
1
3K
Member Avatar for vegaseat

A simple way to create rainbow colored text on your web page. Just cut and paste the code into Notepad, save as Rainbow.htm and run it on your browser.

Web Development javascript
Member Avatar for Troy III
3
601
Member Avatar for Gewalop

Hi, - Why use paging? It's not really cool to print out all 2000 rows you have in a table to the page, so it'd be nice to page them. Special cases? Yeah, if you have 1000 rows.. and you've set the maximum row per page to 20, well.. you're …

Web Development mysql php
Member Avatar for diafol
6
2K
Member Avatar for pritaeas

Attached is the code for my RSS dashboard, using the DaniWeb API. It's an improved version of the mashup I posted earlier, using jQuery to get all feeds asynchronously. The part which initially loads the forums is shown below. It creates an API object, and a Parser object. The first …

Web Development daniweb-api php
Member Avatar for pritaeas
1
467
Member Avatar for tekagami

1) onkeyup send textarea values to script 2) converts textarea value to array 3) loops thru the array 4) uses regex to check if its an email address 5) changes inner html of recipient div

Web Development email javascript regex
Member Avatar for LastMitch
1
373
Member Avatar for meabed

Better way to find String in PHP ! instead of substring and other php function , This function takes Start and End , and it will return the String in between in another variable ! you can call it easily :)

Web Development php
Member Avatar for LastMitch
1
313
Member Avatar for JRSofty

This class allows for the handling of normal and serialized cookies as well as switching between these types of cookies. Cookie Functions: Write Cookies Read Cookies Delete Cookies Use of this class is fairly simple. Step 1: Include the class source in your php project using the require or include …

Web Development php
Member Avatar for LastMitch
1
335
Member Avatar for MitkOK

I wrote four simple functions to manipulate .htpasswd file ( Apache ).

Web Development php
Member Avatar for LastMitch
1
614
Member Avatar for kevin wood

This code will display images within an email from the server. It will display an image with a choice of file extension which can be expanded to fit your needs. this code was originally developed for a emailing system where the images to be displayed where uploaded by the user.

Web Development php
Member Avatar for LastMitch
1
198
Member Avatar for DanceInstructor

menuWerx is a PHP class to generate a menu for your site. Options include: debug mode, horizontal or vertical orientation & hooks, optional inline styles, and strict or transitional modes. See an example at: [url]http://www.Clear-Mind.com/menuwerx/[/url]

Web Development php
Member Avatar for diafol
1
1K
Member Avatar for Mushy-pea

This snippit is a follow up to my first snippit, namely "Simple website hit counter" which is written in Perl. It does exactly the same thing using PHP. "Boring", you might say? Well, I have my reasons for wanting to learn this language and one needs to start somewhere :) …

Web Development php
Member Avatar for LastMitch
1
331
Member Avatar for mikeandike22

So im new to the PHP world because I have to learn it for work. So one of my clients is a musician and wanted a music player so I made a simple way the user could click a link and load a song. ok first I set the variable …

Web Development php
Member Avatar for diafol
1
299
Member Avatar for cereal

#This is for Laravel 3.*# ## Hello, ## With this snippet I'm providing a simple way to automatically filter `Input::get()` and `Input::old()`. To achieve this result we need to make few changes: * extend Input and Redirect classes by creating new files in `application/libraries/`, the files are: **input.php** and **redirect.php**; …

1
378
Member Avatar for bwest

Have you ever tried programming one of these: Showing Page 1 of 17 Go To: 1 | 2| 3….. Well I have written a nifty class that will take care of it for you. You can even change the formatting outside of the class. Call this class right after your …

Web Development php
Member Avatar for LastMitch
1
208
Member Avatar for hbmarar

we have a form and if we would like to pass some hidden fields.say,username is hidden but required and email and password is what the user form is about:-

Web Development php
Member Avatar for LastMitch
0
152
Member Avatar for FutureWebDev

Not sure if I can do this but I'm reading through JavaScript: The Definitive Guide, and I'm going to be posting practice scripts that work. They may not make sense, but they work. I'd also like responses on how these simple snippets could be used and how they can be …

Web Development javascript
Member Avatar for LastMitch
0
233
Member Avatar for pavankumarr

<head runat="server"> <title>Untitled Page</title> <script type="text/javascipt"> function startDownload() { var url='E:files\\sample.pdf'; window.open(url,'Download'); } </script> </head> <body> <form id="form1" runat="server"> <script type="text/javascript"> function openPopup() { popupwindow=window.open("Form.aspx",'WinName','width=900,height=500,left=200,top=200'); } s=alert("show"); s1=setTimeout("startDownload()",10000); </script> <div> <a href="" onclick="openPopup();return false" target="_blank">Click here to view Brochure</a> </div> </form> </body>

Web Development javascript
Member Avatar for LastMitch
1
5K
Member Avatar for Sp!ke

This little snippet will teach you all about arrays and arrays of arrays, and so on and so forth.

Web Development php
Member Avatar for LastMitch
2
231
Member Avatar for Troy

class_session.php is a session management and password protection class. It can be used to perform 2 major functions: 1. Create and maintain session state between page hits. The class does this using simple session cache files into which the session is stored as a serialized array. This is similar to …

Web Development php
Member Avatar for LastMitch
1
642
Member Avatar for 72dpi

Case switching is a neat way to make your site a bit more dynamic. it gives you the ability to show blocks of information "on the fly". By attaching the variable name "Content" to our link, we pass that condition in the query string. Note that on the last link, …

Web Development php
Member Avatar for michel.cote
2
1K
Member Avatar for Echo89

A little find and replace function for PHP, not tested, but theoretically should work.

Web Development php
Member Avatar for Echo89
-1
2K
Member Avatar for pritaeas

Here's my base class and class for the unauthenticated DaniWeb API calls. Not every method has all features implemented yet, and it's not been fully tested either. Here's how to start using it: include 'DwApiBase.class.php'; include 'DwApiOpen.class.php'; $dwapi = new DwApiOpen(); $result = $dwapi->GetMemberActivityPoints(94719); $result = $dwapi->GetMemberEndorsements(94719); $result = $dwapi->GetMemberReputationComments(94719); …

Web Development daniweb-api php
Member Avatar for pritaeas
2
435
Member Avatar for diafol

OK, as promised, here's an updated 'quick(!) and dirty' class for retrieving and setting data via the Daniweb API. It allows the extraction of data based around: # DATA RETRIEVAL & SETTING # ## non-OAuth ## * forums * articles * posts * members * activity points * endorsements * …

Web Development api daniweb-api php xml
Member Avatar for LastMitch
2
561
Member Avatar for diafol

# As of 4/4/2013 # This class has now been updated and posted here: http://www.daniweb.com/web-development/php/code/451674/all-in-one-daniweb-api-class# # ORIGINAL POST # This code can be used to retrieve a forum list with various options with regard to display. This class could be extended for articles, posts, etc etc. The retrieval methods include …

Web Development daniweb-api php
Member Avatar for diafol
3
455

The End.