Category : "Coding"

All kinds of Programming.

Create foreign key using Phpmyadmin

The innodb storage engine supports foreign keys in Mysql. To create foreign keys in phpmyadmin : 1. Convert both tables into innodb, if they are not already. 2. View the structure of the table which will have a foreign key. Make the referencing field an INDEX. 3. Now come back to structure view and click Relation view. In the Relation view page the field (which ...

Import mysql dump files with view definer and sql security

Views and mysqldump A little back I tried to backup a database from my webhost and restore it on my localhost mysql. It had a few views. The import of the sql file seemed to work fine. But on accessing the views in phpmyadmin mysql gave the error : #1449 - There is no 'projects'@'localhost' registered The problem is with a security feature ...

Create AutoIncrement column/field in Apache Derby

While creating a table a particular column / field can be made autoincrement as : CREATE TABLE students ( id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(24) NOT NULL, address VARCHAR(1024), CONSTRAINT primary_key PRIMARY KEY (id) ) ; The value of an autoincrement column increments automatically with every insert and doesnt need to be specified in the insert command. It ...

PHP redirect – go back to previous page

To go back to the previous page the superglobal variable $_SERVER can be used. $_SERVER has the link to the previous page. So to redirect simply : #Method to go to previous page function goback() { header("Location: {$_SERVER}"); exit; } goback(); ...

PHP Format numbers to Indian Numerical System

The numerical system used in India differs from the Western system in terms of the placement of the thousands separator. Example : Number -> 1000000 Indian System -> 10,00,000 (Ten Lakh) Western System -> 1,000,000 (1 Million) While echoing numbers in PHP it is possible to format numbers with such separators using functions like number_format. To format a number in the Indian Numerical System ...

Create short links using bit.ly from php

bit.ly is a simple url shortner which has an api , which can be called from within php to shorten links. Code : function get_short_url($url) { $bitly_login = "your_login_name"; $bitly_apikey = "your_api_key"; $api_call = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitly_login."&apiKey=".$bitly_apikey); $bitlyinfo=json_decode(utf8_encode($api_call),true); if ($bitlyinfo == 0) { return $bitlyinfo; } else { return false; } } The above function can be used to shorten a big url , as : if ($shortlink = get_short_url("http://www.google.com/")) { echo $shortlink; } ...

Code raw sockets in C on Linux

Raw tcp sockets in C Raw sockets can be used to construct a packet manually inside an application. In normal sockets when any data is send over the network, the kernel of the operating system adds some headers to it like IP header and TCP header. So an application only needs to take care of what data it is sending and ...

SYN Flood DOS Attack with C Source Code (Linux)

TCP/IP 3-way handshake is done to establish a connection between a client and a server. The process is : 1. Client --SYN Packet--> Server 2. Server --SYN/ACK Packet --> Client 3. Client --ACK Packet --> Server The above 3 steps are followed to establish a connection between source and destination. SYN Flood DOS attacks involves sending too many SYN packets (with a bad or random ...

PHP: Get visitor’s location, city, country from IP address

Ip to Location Many applications need to get information about the geographical location of the user/visitor on their websites. This can be done in many ways. There are online services like ipinfodb and geoio that provide web based api to get the geolocation information about a given ip address. Services like Maxmind geoip provide free database that can be installed on ...

Parse and change date format in php

Parsing dates Most php applications need to parse dates and convert them to timestamps for example. Parsing is also necessary to convert the date into a more standard format like yyyy-mm-dd which can be stored in a database like mysql. Mysql database stores dates in the format yyyy-mm-dd like 2009-04-15. However humans are more used to the formats like dd-mm-yyyy or mm-dd-yyyy ...



Connect with us