331 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for Dani

The Markdown editor that we use here at DaniWeb is called [CodeMirror](https://codemirror.net/) and we've been using it for forever. The other day, I noticed some bugs in the editor toolbar that we use, which is based on the [CodeMirror API](https://codemirror.net/docs/ref/). (The one that allows the buttons for bold, italic, etc.) …

Web Development typescript
1
56
Member Avatar for Chris Hüneke

Never published this before, so this is a DaniWeb.com Exclusive :) If your WP-Site has a lot of K-Links, you should consider using this script. It definetly works. For now... ## **Negative SEO** through spamming Backlinks can be a huge problem for the visibility of a webpage. ## You can …

Web Development apache seo wordpress
Member Avatar for amastyteam
2
968
Member Avatar for Dani

DaniWeb is built on top of the Codeigniter 3.1.x PHP framework. Although I probably should have built it as a CI model, here is the database library that we are using. You can see it mainly serves as a wrapper for CodeIgniter's built-in database class. You can see we use …

Web Development php
Member Avatar for pyeri
2
318
Member Avatar for Troy

This is a simple to use, self-contained website slideshow utility. Do you have a monitor or TV setup in your lobby where you'd like to present web content automatically? With this HTML/Javascript page, simply edit an array of pages or "slides". You define a title, duration, and URL for each …

Web Development javascript
Member Avatar for PROSYS_1
1
15K
Member Avatar for jkon

I wanted to post something in Daniweb for a while but I didn't had anything new. Recently I decided to write a new implementation for websocket connections client side using Shared Web Workers. Shared Web Workers are supported today by most browsers for desktop but few for mobile devices , …

Web Development javascript
Member Avatar for jkon
2
464
Member Avatar for olaf

This function is usefull for peoples with a link directory where the links are stored inside a (MySQL) database. The PHP script is easy to use to find out if a reciprocal link still exists on the corresponding webpage. It takes care about the trailing slash in urls and can …

Web Development php
Member Avatar for Dani
0
183
Member Avatar for Dani

Here is the function that I use here at DaniWeb to manage flood control. It keeps track of how often a specific user or IP address is making a request, and increments a counter. If there have been no requests after 5 minutes, the counter resets to 0. It returns …

Web Development php-codeigniter redis
Member Avatar for Dani
4
483
Member Avatar for Dani

Sometimes we have a need to take a simple PHP array and represent it as an encoded string. One use case that we have for this at DaniWeb is when a new user signs up, and we ask them to click on a link that was sent to them via …

Web Development php
Member Avatar for Dani
2
231
Member Avatar for Dani

Sometimes we want to know if the webpage was fetched over an SSL connection (e.g. the URL begins with https:// instead of http://). This way, if an end-user is accessing an insecure version of our site, we can redirect them to the secure version. The following PHP function called `no_ssl()` …

Web Development php
2
232
Member Avatar for Dani

For some reason, PHP class constants don't play nicely with inheritance. For example, suppose you have the following code: class Foo { const VAR = 'foo'; public function __construct() { echo self::VAR; } } class Bar extends Foo { const VAR = 'bar'; } // This will actually print out …

Web Development php
Member Avatar for Dani
1
361
Member Avatar for Dani

By default, PHP's clone keyword just creates a shallow copy of an object, and doesn't work as desired if the object contains properties that are also objects, because it doesn't create real copies of those objects but rather just pointers to the initial version of them. This function creates a …

Web Development php
0
295
Member Avatar for Dani

A little while ago, I wrote a [tutorial](https://www.daniweb.com/programming/web-development/tutorials/537376/sanitize-php-user-input-strings) about how important it is to sanitize PHP user input strings. Not only is it important to sanitize user input being fed into a database query, but it's also important to sanitize user input being displayed to the end-user to generate valid …

Web Development html-css php
2
276
Member Avatar for martin5211

FPDF is a class that provides a useful way to deal with PDF documents using dynamic content. Sometimes, according to a special circumstance, also would be valuable to send directly the PDF as attachment e.g. send an invoice automatically after processing a payment. In this example we use a html …

Web Development pdf php
Member Avatar for Dani
0
22K
Member Avatar for Fungus1487

I browsed google and found nothing so thought i would put my efforts up here. hope this all helps. this function will allow you to return the number of days between two dates minus saturdays and sundays. (including the start date)

Web Development javascript
Member Avatar for pritaeas
0
3K
Member Avatar for shilpa647

After page loading , when I click on the ellipsis , horizontal tabs transform from bottom of the product image . After opening of the tabs menu bar , first tab should open by default.I tried multiple solutions but none of them worked out.

0
211
Member Avatar for joshl_1995

Hello Daniweb Community, I have been talking on a couple [Facebook](http://www.facebook.com) groups such as sale pages where you post your own stuff for people to buy. Most groups like this have rules about bumping like once per day, every 12 hours etc... So it got to the point where it …

Web Development php social-media
Member Avatar for Mark_109
4
3K
Member Avatar for Tko_1

I needed a script that would grab all the folders in the directory and add them to a dropdown list and allow the user to upload to there choosen folder. This is what i came up with. (upload script is not mine) Thought i would share.

Web Development file-system php
Member Avatar for rproffitt
0
4K
Member Avatar for serkan sendur

As usual i searched google to convert Decimal numbers to their Binary equivalents but i couldnt find any short algorithm for that matter. So here is mine..

Web Development javascript
Member Avatar for Deendayal_Hindu
1
3K
Member Avatar for NardCake

Hello! I needed a configuration file for a application I'm working on so I first used the built in ini functions in php but it wasn't easy to write the ini files. So I wrote myself a class here to parse a configuration file and write/edit configuration files. I plan …

Web Development php
Member Avatar for Vitaly_1
2
959
Member Avatar for Dani

If you need your PHP script to redirect to a different website, you can send an HTTP header to do that. Remember, `header()` must be called before any actual output is sent, which includes not just HTML, but blank lines, etc.. as well.

Web Development http-protocol php
Member Avatar for bngwebguru
0
3K
Member Avatar for Dani

This is the code behind the demo at https://www.daniweb.com/connect/oauth/demo

Web Development php
1
3K
Member Avatar for Dani

You might be familiar with the dreaded blank page when your PHP script doesn't work. Here's how to spit out errors to the screen, instead of getting just a blank page, as well as logging errors to a file.

Web Development php
1
2K
Member Avatar for Dani

There are two ways to write to a file in PHP. You can either open a stream, and write to it in parts, or you can use `file_put_contents()` which is much more convenient, with the trade off being that it takes up much more memory, and is not ideal if …

Web Development php
0
2K
Member Avatar for Dani

This code dynamically generates a clear 1x1 pixel.

Web Development php
0
2K
Member Avatar for paulkd

...was asked for some php file upload code, so I thought I would post some stripped down, barebones code that I use in admin/dashboard pages to add/change images associated with products. Please see attached image for folder setup. The code uses the [jQuery Form](http://malsup.com/jquery/form/) plugin by Mike Alsup. **index.php** has …

Member Avatar for NaReSh_12
1
11K
Member Avatar for Dani

I recently had to mass insert a really large text file of strings into MySQL. Here's how I did it.

Web Development mysql php php-codeigniter
Member Avatar for PARDEEP_2
1
1K
Member Avatar for Raju_3

I am building an e-commerce website i found one error in last night in my site Error: If user enters the zipcode in zip code field & without clicking on CHECK OR GO Button, when he clicks on ADD TO CART button then products are getting added in Shopping cart. …

Web Development wordpress
0
604
Member Avatar for AleMonteiro

Hello everybody. I'm starting to build an event calendar for employees in my company, and the first thing I needed was an working calendar to build from, so I wrote a simple one. Hope it can be usefull for someone. Cheers.

Web Development javascript
Member Avatar for Mike_40
3
2K
Member Avatar for jkon

I found myself starting to answer a question that I have answered many times , so I thought why not making a code snippet and just reference this. This is a short code snippet only to demonstrate how this thing work (with apache and rewrite engine on) , in real …

Web Development php
Member Avatar for jkon
2
663
Member Avatar for rajesanthu

The Code Given is for only beginners in HTML 1.The code implements a simple login form 2.It checks whether the password and usernames are matching or not 3.While you are using replace the predefined username and password that I'v given that is replace "myuserid" and "mypswrd" with your own userid …

Web Development html-css javascript
Member Avatar for nate_2
0
137K

The End.