Skip to main content

ยท 2 min read

Nowdays, mostly all of the site/blog owners are frustrated because of spammers, they put spam/phishing links in comments and contact forms also, whenver our geneuine users using site they may face problem because of this.

Now let's see how we can implement this,

assets/images/captcha.php
<?php
session_start();
if(isset($_SESSION['captcha']))
{
unset($_SESSION['captcha']);
//removing if captcha already set for session
}

$string1 = "abcdefghijklmnpqrstuvwxyz";
$string2 = "123456789";

$string = $string1.$string2;
//From these 2 random string will be generated
$string = str_shuffle($string);
$rand = substr($string,0,5);

$_SESSION['captcha']=$rand;
//setting new captcha string

/* Create an image in php */

$myimg = imagecreate(100, 30);
$background = imagecolorallocate($myimg, 199, 144, 225); // background color
$text_colour = imagecolorallocate ($myimg, 245, 245, 245); // text color
imagestring($myimg,12,25,8,$_SESSION['captcha'],$text_colour); // add captcha code in image
header ("Content-type: image/png");
imagepng ($myimg); // displayed image createde
imagedestroy($myimg); // remove allocated memory.

?>

Now on the login page just use one image tag with src as the path of captcha.php, and check the if captcha is valid using the session.

for example.

login-validate.php
<?php
session_start();
if(isset($_SESSION['captcha']))
{
if($_SESSION['captcha'] == $_POST['captcha']){
echo 'valid captcha';
}
else{
echo 'Invalid captcha';
}

}
else{
echo 'Please complete captcha';
}


?>

Now you can easily integrate this code in all of your pages where you expect the input from users.

ยท 11 min read

Installationโ€‹

Uploading Filesโ€‹

To upload files, first we need to download them from EasyURLs repository

You can download any stable release here

Once source code is downloaded. Now visit your website's CPanel. You can access your cpanel from your hosting provider's site or you can directly access using cpanel.yoursite.com or yoursite.com/cpanel .

Once you accessed your CPanel we will be moving to upload our files on CPanel Account . To upload click on File Manager and Go to Public_html folder and create desired folder. How to Install FREE EasyURLS on CPanel in 5 minutes?

Suppose you want to add your software at example.com/url then create a folder url inside your public_html folder.

Now upload the .zip file we downloaded from above link. Now we have to extract that file. After extraction, you will get a folder with the same name as our zip file name. Now we can securely delete that zip file. Now move the content from our EasyURLs-master . folder to our link folder.

tha's it. we completed our first task to upload required files to the server.

Database Partโ€‹

Creating Databaseโ€‹

To create database click on MySQL Databases. see image below. option 1 to be selected. How to Install FREE EasyURLS on CPanel in 5 minutes?

Once you click you will be redirected to page where it will ask you the name of database. You have to enter database name you want to use. Keep Good & understandable database name & click on Create Database. How to Install FREE EasyURLS on CPanel in 5 minutes?

Creating A Userโ€‹

Once the database is created. we have to create a user to access the database we just created. To create users just scroll down. You will get the option to Add New User. Create a username & you can use a password generator to generate passwords. Keep all this data safe and secure. we need all this data while setting up your app. How to Install FREE EasyURLS on CPanel in 5 minutes?

Authorizing the user to use databaseโ€‹

The last step & important step is to authorize user to use our database. Just scroll more you will find Add User to Database option. How to Install FREE EasyURLS on CPanel in 5 minutes?

Now select the user and appropriate database and click on Add button. Now you will be redirected to another page. Where you are required to select the rights to users on the database. simply select ALL PRIVILEGES. How to Install FREE EasyURLS on CPanel in 5 minutes?

Now click on Make Changes . Done, we have done database part too.

Configurationโ€‹

Note : If needed you can install free ssl certificate, to install ssl please read this article

Now visit yoursite.com/link or yoursite.com on which path you uploaded files in last step, it will redirect you to yoursite.com/install.php

Installation Process

In form below enter the following details, to install application.

  • Host : If you are installing on same server use localhost, if you are using external database make please use IP Address and port 3306 e.g. 1.1.1.1:3306, You have to start access in MySQL remote database else it will not work
  • Database username : enter username generated in last step
  • Database Password : enter db user's password
  • Database Name : now database name

Important : If you see error, please check your database credentials, if those are correct and you are still facing issue then please give database access to user Read more

If you don't see any errors, then you completed setup correctly, In next step enter

  • Username : this is just short name for login e.g. admin,peter etc.
  • Email : enter valid email id, After new update you will be able to reset your password with this mail, So enter correct mail id.
  • Password : Use strong password, keep it secure.

Click on Complete Installation, Now it will show that installation has been completed. it will take you automatically to login page.

note

If you face any issue during installation & unable to complete installation, Please delete config.php file and start process again, also create database again

loginโ€‹

danger

After successful installation, it automatically deletes install.php and install2.php, if it does not delete, Please delete both files manually.

Visit yoursite.com/login.php to login your site, enter email or username and password & click login to access dashboard.

Managing EasyURLSโ€‹

Link

Creating URLโ€‹

After login click Manage URLS on navigation bar now you can see all the links created by you as we are creating our first link click on add new link enter long URL after that enter short URL it will show you availability, if the URL is available click on add it will create short url. To copy short url, Right click on short code and click Copy Link Address

Deleting URLโ€‹

To delete URL Manage Links --> All Links, Click Delete button next to any url to delete that URL

Editing URLโ€‹

In current version of EasyURLs, it's not possible to edit any url, But you can delete old url and add new url.

Searchingโ€‹

To search short url just start typing in above search bar, it will automatically filter urls, with your search query.

Download Excelโ€‹

You can download excel file of all the urls generated, to download visit Manage Links --> All Links --> Download Excel, it will download .xls file, if you see any warning please ignore the excel file is safe to use.

Managing Usersโ€‹

Link

Adding Usersโ€‹

After login click Manage Users on navigation bar now you can see all the Users in system.Click on Add New Link enter Email,Username,Password, if the Email and Username is available click on add it will add new user in System.

Deleting Userโ€‹

To delete URL Manage Users --> All Users, Click Delete button next to any user to delete that User

Password Resetโ€‹

Just click on Reset button next to email of user and it will generate temporary password for the user, you can share with user and after that they can change their password from their profile.

Searching Usersโ€‹

To search user url just start typing in above search bar, it will automatically filter users, with your search query.

Download User Excelโ€‹

You can download excel file of all the users generated, to download visit Manage Users --> All Users --> Download Excel, it will download .xls file, if you see any warning please ignore the excel file is safe to use.

Managing Profileโ€‹

Link

You can edit your username, email and password, Just click on whatever you want edit and add new value then click update.

Make sure if you don`t want to change password then keep those fields as it is, same for username and email.

APIโ€‹

Link

Adding Keysโ€‹

After login click API on navigation bar now you can see all the API KEYS in system.Click on Add New API KEY then enter KEY NAME, please note that key will be auto-generated, after that click on Add New API Key it will add new API KEY in System.

Deleting Keyโ€‹

To delete URL API --> All KEYS, Click Delete button next to any KEY to delete that API KEY, Once key is deleted all the applications using that key will stop working.

Editing Keyโ€‹

You can not edit any key, But you can delete and create new key.

API Guideโ€‹

You can use API once you generate api key.

To get all links with details use

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `LINKS`

You will get response in json , for e.g.

response.json
[
{
"ID":"1",
"SHORT_URL":"pDWOBz",
"LONG_URL":"https://www.google.com",
"COUNT":"0"
},
{
"ID":"2",
"SHORT_URL":"CIKH-f",
"LONG_URL":"https://microsoft.com",
"COUNT":"0"
},
{
"ID":"3",
"SHORT_URL":"FnMDHT",
"LONG_URL":"https://kaustubhk24.netlify.app",
"COUNT":"0"
},
{
"ID":"4",
"SHORT_URL":"an2pr6",
"LONG_URL":"https://justinclicks.com",
"COUNT":"0"
},
{
"ID":"5",
"SHORT_URL":"Esh4Cg",
"LONG_URL":"https://example.com/affiliate",
"COUNT":"0"
}
]

To get specific link with details use

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `VIEW`
`LINK_ID` : int LINK_ID e.g. 1

You will get response in json , for e.g.

response.json
[
{
"ID":"6",
"SHORT_URL":"UMYi2",
"LONG_URL":"https://facebook.com",
"COUNT":"0"
}
]

To add new link we have 2 ways

If you want specific short link for given long_url, please pass params as follow

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `ADD`
`SHORT_URL` : short_url you want to set, do not use domain, use only code e.f. xyz
`LONG_URL` : LONG_URL is url where you want to redirect your short url

If you want to generate short code automatically

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `ADD`
`LONG_URL` : LONG_URL is url where you want to redirect your short url

You will get following response in both cases,

response.json
URL added[
{
"ID":"6",
"SHORT_URL":"UMYi2",
"LONG_URL":"https://facebook.com",
"COUNT":"0"
}
]

To delete link

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `DELETE`
`LINK_ID` : int LINK_ID e.g. 1

You will get following response

response.json
Deleted

Managing Usersโ€‹

Getting All Usersโ€‹

To get all users with details use

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `USERS`

You will get response in json , for e.g.

response.json
[
{
"USER_ID":"1",
"USERNAME":"kaustubh",
"EMAIL":"info@example.com"
},
{
"USER_ID":"2",
"USERNAME":"kk",
"EMAIL":"info@example.com"
}
]

Getting Specific Users Detailsโ€‹

To get specific user with details use

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `VIEW`
`USER_ID` : int USER_ID e.g. 1

You will get response in json , for e.g.

response.json
[
{
"USER_ID":"1",
"USERNAME":"kaustubh",
"EMAIL":"info@example.com"
}
]

Adding Userโ€‹

To add user

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `ADD`
`EMAIL` : users email
`USERNAME` : username for login
`PASSWORD` : send non-encrypted password, it will be automatically encrypted.

You will get following response

response.json
User added[
{
"USER_ID":"14",
"USERNAME":"test",
"EMAIL":"in@demo.com"
}
]

Deleting Userโ€‹

To delete user

Request
// base url
your_domain.com/api.php

Request type : `GET`

// following parameters are required

`API_KEY` : Enter key you generated in last step
`TYPE` : `DELETE`
`USER_ID` : int USER_ID e.g. 1

You will get following response

response.json
Deleted

Common Errorsโ€‹

You may face following issues while using api, so it is recommended to handle all of these exceptions.

  • Invalid Operation : You have to pass correct operation in TYPE parameter, else API request will be rejected with above error.
  • Invalid API Key : Please check if you are passing active API key to API_KEY with no spaces in both sides.
  • Database Not Reachable : Check if your database is not overloaded.

Contributeโ€‹

You can contribute in 3 ways

Core filesโ€‹

While making changes in core files please add comments in code, make sure your code does not break any previously written code.

Translationsโ€‹

To contribute language, please visit assets/local

Editing Current Translationsโ€‹

Visit any language file you want, please note we're using iso language code for file name, for example, file name for Hindi language will be hi.php, After making changes please create pull request.

Adding New Languageโ€‹

To add new language please find correct ISO code of language you are adding and create file with ISO_LANGUAGE_CODE.PHP, for example name for Hindi language file will be hi.php, Now copy the text from sample.php and paste it in file you just created and replace array values as required.

language.php
"Language"=>"Language Name you want to show",
..
...
// Now complete all remaining fields

After that open index.php and add new array key and value for language

index.php
$languages = array(
"English"=>"en",
"เคฎเคฐเคพเค เฅ€"=>"mr",
"เคนเคฟเค‚เคฆเฅ€"=>"hi"
);


Please make sure array key must be Name of language and array value must be iso code of language.

After committing changes please make pull request.

To Sponsor project please visit https://github.com/kaustubhk24/EasyURLs and Click on Sponsor button.

ยท 3 min read

Are you looking for status page for your site/sites? Many times we need to check if our site is working properly or not, So I developed this tool, You can easily host it on GitHub Pages and by just making few changes you can create status page for your website & as it is hosted on GitHub pages, it is completely free to use. See Live App Preview

How to Create Status Page for your site?โ€‹

  • To create status Page first fork https://github.com/kaustubhk24/FREE-Site-Status-Page repository.
  • Go to repository setting and turn on GitHub pages option.
  • In Next Step open file named CNAME & remove text status.justinclicks.com and enter your custom URL. e.g. status.example.com
  • From repo settings enable tick on SSL & update records respectively in your domain DNS settings.
  • Last step is to open main.js & you will see code below, you just need to add your sites there.
main.js
sites=[
{
'site_name':'Example.com',
'site_url':'https://www.example.com/'
},

{
'site_name':'Sub Example',
'site_url':'https://sub-domain.example.com/'
}
]
  • Now at the place of site_name you have to enter your site Title & in site_url enter exact URL of your site with http or https properly.
  • Make sure you haven't kept any previous site name, just remove all of them & add yours
  • Now create file in incidents/ folder with site name for example if your site name is Example Site in main.js then your file name will be Example Site.json, Do not remove spaces or anything , use exact site name from main.js & keep file in incidents/ folder .
  • To report incident open your site file from incidents/ folder, & copy content below there
incidents/site_name.json
[
{
"incident_name":"incident_name at time",
"description":"description"
},
{
"incident_name":"incident_name 2 at time",
"description":"description 2"
}
]

  • Make changes according to your requirements, that's it
  • Done ! Once GitHub Build pages your site status page will be Live.

Issuesโ€‹

Live Preview GIFโ€‹

Status PageIncidents Page
Status PageIncidents Page

Disclaimerโ€‹

We have tried our best to keep the code bug free, users are requested to confirm information with their sites before using the information provided. The author reserves the right not to be responsible for the topicality, correctness, completeness or quality of the information provided. Liability claims regarding damage caused by the use of any information provided, including any kind of information which is incomplete or incorrect, will therefore be rejected.

Licensingโ€‹

You are free to download / modify / sell code but with terms below but not limited to,

  • You should not remove footer credits and links
  • You can not add your footer credits
  • You should remove JustInClicks links from main.js files, you should keep only your links
  • All use and/or publication rights are reserved worldwide.
  • Copyrights ยฉ 2021 Kaustubh Kulkarni { Kaustubhk24 }

ยท 2 min read

Statement > Suppose you have an array of numbers and you have to create a function that will accept 2 parameters an array and rank, you have to print the highest rank number from the array to know more read the example below.

Example :

Example Input
Input
arr=array(10,25,55,66,48,33,22,13,98,95,96)
rank=2
Then Output should be 2nd highest element of array i.e. 96

Example 2>

Example Input 2
Input
arr=array(10,25,55,66,48,33,22,13,98,95,96)
rank=3
Then Output should be 3rd highest element of array i.e. 96

Important : First, try your own logic & then see answers, if you think you have better logic than the article please drop a comment, we'll publish your code

Logic >

Basically, we have to find the nth highest element from the given array, We will use a simple method, Just sort the array in descending order and call print n-1th element (as array starts from index 0)

If you get similar question with another logic like find nth smallest element from the given array, then just sort array in ascending order

please read programs below for reference.

Program in PHP
<?php
function getByRank($arr,$place)
{
rsort($arr);
echo $arr[$place-1];
}
$arr = array(1,2,5,97,9,55,78,55,93,98);
getByRank($arr,2);
?>

Code in Python >

Program in Python
def getByRank(arr,pos):
arr.sort(reverse=True)
print(arr[pos-1])
arr=[12,15,96,98,55,65,33,22]
getByRank(arr,3)

Java Code >

Program in Java
import java.util.Collections;
import java.util.Arrays;
public class HelloWorld{
public static void main(String []args){
int arr[]={33,3,4,5};
int pos=2;
Arrays.sort(arr, Collections.reverseOrder());
System.out.println(arr[pos-1]);
}
}

ยท One min read

Given a matrix, find the transpose of a matrix.

Input
Input 
2
4
1 2 3 4
2 9 -1 2

Where,

First-line represents the number of rows as M. Second-line represents the number of columns as N. The third line contains matrix elements of 1st row and so on.

output
Output 
1 2
2 9
3 -1
4 2

Program >

Transponse.java
// DriverMain.java
import java.util.*;
public class DriverMain {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int r = s.nextInt();
int c = s.nextInt();
int first[][] = new int[r][c];
for (int i = 0; i < r; i++){
for (int j = 0; j < c; j++){
first[i][j] = s.nextInt();
}}
for(int i = 0; i < c; i++)
{
for(int j = 0; j < r; j++)
{
System.out.print(first[j][i]+" ");
}
System.out.println(" ");
}
}
}

Output >

output
Input

2
4
1 2 3 4
2 9 -1 2
Output

1 2
2 9
3 -1
4 2
Expected Output

1 2
2 9
3 -1
4 2

ยท One min read

Que > Write A Python Program To Create File And Write 1 To 100 Numbers, print each number on new line

Program >

write-numbers.py
def writeNumbers(F):
temp=""
for i in range(1,101):
temp+=str(i)+"\n"
F.write(temp)
f=open('text.txt','w')
writeNumbers(f)
cmd
$ python write-numbers.py 
output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

ยท One min read

Que > Write a program to read Name and age of person from file named โ€˜file.txt' and print if person is eligible for voting or not.

file.txt
Your Name,24
Program.py
def checkAge(name,age):
if (int(age)>18):
print(name+" is eligible for voting")
else:
print(name+" is not eligible for voting")
f=open("file.txt")
content=f.read()
data=content.split(",")
checkAge(data[0],data[1])

Output > Output

ยท One min read

Code >

file.py
import matplotlib.pyplot as plt
import matplotlib.image as img
testImage = img.imread('https://kaustubhk24.netlify.app/imgs/wp-content/uploads/2021/05/python-programming-language-1.png')
plt.imshow(testImage)
print(testImage)

Output >

Output
[[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
...
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
...
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]]

Python

ยท One min read

Code >

file.vb
import pandas as pd
data = {'Name': ['Snake', 'Prince', 'Gangsta', 'Wolf'],
'City':['Pune','Nasik','Kolhapur','Bangalore'],
'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}
df = pd.DataFrame(data)
print("Old:\n",df)
df.insert(1, "Age", [21, 23, 24, 21], True)

Output > (OLD)

Output

**Old:**
Name City Qualification
Snake Pune Msc
Prince Nasik MA
Gangsta Kolhapur Msc
Wolf Bangalore Msc

New > (OLD)

NameAgeCityQualification
Snake21PuneMsc
Prince23NasikMA
Gangsta24KolhapurMsc
Wolf21BangaloreMsc