Tuesday, 14 April 2020

Google API Update Alert 1 | Google Sheet And Google Calendar With PHP | ...




Download VENDOR Folder (Only for PHP version 7.2+): https://unpossiblepog.com/research-and-development/php/Vendor-Folder-For-Google-Sheet-Drive-Calendar-With-PHP-Version-7.2-And-Onward

Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------

Google Sheet API | Part 1 | Connect And Display Sheet Data Using PHP | Latest:
https://youtu.be/CI0xL93Xtpg

Google Sheet API | Part 2 | Create New Sheet | Add & Update Cell Values:
https://youtu.be/X9h47ht-NnY

Google Sheet API | Part 1 | Connect And Display Sheet Data Using PHP | Latest:
https://youtu.be/Q-498CAa1xE

Google Calendar API Tutorial #2 | Access Different Calendars Using PHP:
https://youtu.be/9FfWnfpx9Kw

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------

Hey guys.
Google recently added some extra steps, for security reasons, while we create credentials for developing APIs for PHP.
It is making direct impact on my 4 tutorials on GOOGLE APIs which are on google sheet and calendar so I had to make this video as soon as possible.
Plus the process has a huge bug. I shall tell you how to bypass that bug and make the code work.
In this case I am using google sheet, but steps are similar for google calendar too.
Here you will see that, I created a folder in HTDOCS of xampp.
If you go to quickstart, and click on enable API, there is an extra INPUT you have to do. For my 4 tutorials, you have to select “web server”, and give the path which is for security reason so that no other website will access same API and code.
I am using localhost just for testing, and folder name as “google_update”, make sure to have same folder on both sides, and I shall give the name as quickstart.php. You will see that quickstart file later.
Download the credentials.
Paste it in that newly created folder.
Open that folder in terminal.
execute the command they provided.
Once done, copy the php code, create a new file as quickstart.php in our folder. Paste the code.
Make changes as same as I do in that code.
In terminal, make sure you are in that folder, then execute this command.
When clicked on “ALLOW”, you will see a huge bug.
The output was supposed to be like this. but, they provide you verification code in URL.
This change was done by google in coronavirus quarantine so it is possible they they didn’t get time to test it.
I understand that they are human too, they will fix it.
If you observe, the process directly executed the file.
So just copy the verification code and paste it in terminal.
hit enter. And you will be connected with API.
Now what you can do is comment those lines and then execute file in browser.
You can execute it without any request variables.
Sometimes you get error like this for token.json which says “file_put_contents(token.json), permission deined”
So just go to it’s properties and make it executable for everyone by changing the permission.
Now you can continue watching my tutorials.
Don’t forget to like, share and subscribe.
Required links are given in the description.
Thanks for watching. 


Thursday, 9 April 2020

Google Sheet API | Part 2 | Create New Sheet | Add & Update Cell Values


------------------------------------------------

Download VENDOR Folder (Only for PHP version 7.2+): https://unpossiblepog.com/research-and-development/php/Vendor-Folder-For-Google-Sheet-Drive-Calendar-With-PHP-Version-7.2-And-Onward

Hey guys, this is UNPOSSIBLE POG.
In previous part, we saw how to connect GOOGLE SHEET with PHP, and display data. If you haven’t watch that, then you can click on top corner or link is given in the description.
In this part, we shall learn how to create new spreadsheet and how to add & update data in it.
First of all, I shall get rid of those comments.
Then first we shall learn how to create new spreadsheet.
Go to the link that I provided in description, copy the code in PHP tab, comment previous display code, from below service variable up to bottom.
We shall paste it here.
Add any title you want.
And execute it.
It will respond with spreadsheet ID.
Lets go to google sheet’s home page, and you will find that spreadsheet.
Remember that newly created sheet always creates subsheet named “sheet1“ inside it by default.
I shall just delete it because I am not going to use it.
Next is to add & update data in out sheet.

We shall need spreadsheet ID and range.
Go to the description and click on "Add / Update spreadsheet values” link.
Skip that “Writing to single range”, because it is useless.

But before that, we shall append values, means add new rows in spreadsheet.
Copy the code, paste it after range.
Now I am going to add two new rows. So follow my format.
Notice that we are only adding 3 columns that is from A to C.
2 after A doesn’t matter right now.
And “VALUEINPUTOPTION” can have two values, either RAW or USER_ENTERED.
RAW means, the data goes as it is as you can see.
“USER_ENTERED” on the other hand performs operation before sending data to spreadsheet.
For examples, it can calculate the values.
As you can see, it showed addition.
But if you use RAW for same syntax, then it gives you an error, so keep a note.
Lets comment it.

We shall use spreadsheet ID & range again. But range now matters the most when it comes to update.
Lets try some data so that, spreadsheet will start updating from 6th row.
Updating data is vary risky so be careful while executing otherwise it can remove your important data.
Now we put 6 so that it will start operation from 6th row.
As you can see, data is replaced.
But what if we add row number which is empty?
It adds new rows in spreadsheet.
So that is it.
Don’t forget to like, share and subscribe.
Required links are given in the description.
Thanks for watching. 
Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------
How to connect with Google sheet and display data:-
https://youtu.be/CI0xL93Xtpg

Create new Spreadsheet:-
https://developers.google.com/sheets/api/guides/create

Add / Update spreadsheet values:-
https://developers.google.com/sheets/api/guides/values

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/

Saturday, 4 April 2020

MS Azure Tutorial | Login Using Microsoft Azure Active Directory And PHP...



Download Whole API with Composed Repository (Only for PHP v7.2 & Plus):- https://unpossiblepog.com/research-and-development/PHP/Magium-Active-Directory-With-VENDOR-For-Microsoft-Azure-SSO-Only-For-PHP-Version-7.2-And-Onward

Hey guys, this is UNPOSSIBLE POG.
In this video, I shall make a connection between microsoft azure and PHP, in short, an authentication using microsoft account through cloud service.
This service is one of the type of “Software as a service” that is SaaS.
As you know, microsoft Azure is a of the cloud-service provider where you can store your data, use it, execute it.
We are using AZURE to authenticate user’s account on their servers rather than our own server or computer.
What do I mean by that?
Suppose you have a website called www.xyz.com, than rather than creating your own login form, you can use microsoft’s login page. So what are the advantage?
Some of them are,
1, if you create your own login page, then it may have loopholes from where hackers can hack into your website. (Loophole maybe like sql injection, bruteforce login)
2, your code can validate email pattern but can not identify if they are real or not. For example if an intruder whats to access your service, then he can create add an email like random-person123@hammer.com which has same pattern as any email but may not exists in real world.
There are many more, but lets skip that for now.

There are 4 important requirements that you need to have.
1) Microsoft account (free trials / Purchased )
2) Should have a live website hosted on servers, with access of CPANEL, WHM or FTP (Filezilla)
3) Any SSL certificate should be installed on that domain. (HTTPS)
4) Linux Operating systems (Debian family) In your PC or LAPTOP with xampp installed in it (PHP version > 7 is recommended)

Lets get started.
Go to portal.azure.com
If you are using trial version, then click on “skip for now”
From top menu, click on “Azure active directory”
 Click on App registration.
Click on “New registration”
Type any random name that you want for application.
Make sure to select Multi tenant (tenant = users) with personal microsoft account.
Platform is optional.
Click on REGISTER.
Now scroll down,  and make select on “YES” on “Treat application as a public client”, and save it.
Then again, click on TOP MENU, “AZURE ACTIVE DIRECTORY”, then select the application we created.
Make sure to copy “APPLICATION (CLIENT) ID”, we need that later on.
Then click on “ADD a Redirect URI”.
You came back to same page of configuration.
Now click on “Add a platform”, and select “WEB”.
Now, I have one website with HTTPS enabled.
For now I shall use that link as redirect URL.
That UNPOSSIBLE_1 is just a folder that I am going to create later in my website, so don’t panic.
Make sure to tick “Access tokens” and “ID tokens”  checked, and click on configure.
You can also tick tokens configuration from here if you want to.
Now click on “Certificates and Secrets”,"New Client Secret”, add random description.
Click on “Add”.
Now make sure to copy this client for later use because next time when you come on same page, they won’t display you the secret value.
Lets again go to, top menu, Azure Active Directory, App registration, you can see that we have certificates ticked for our application.

Now lets jump to PHP.
I provided you the github link the the description.
Download ZIP,
Go to downloaded folder and paste it in HTDOCS folder of XAMPP.
I already downloaded it.
Extract it.
Now rename the extracted folder as the same name that we gave in the folder in my case its “UNPOSSIBLE_1”.
I am using sublime text for editor, but you can you anything like netbeans, notepad++ etc;
Notice that there is a folder called, “examples”, and inside it there is WWW, we are using this index.php as an executable program. So paste that path in redirect URL and save it.
In directories, go to HTDOCS and open your folder in terminal.
Now this is where things get tricky.

Open composer.json file inside your folder and copy those lines and paste it in require array of composer.json file.
Now here, type this.
In terminal type “sudo apt-get install composer” and enter your password.
I already installed composer.

Depending on your php version, type those commands, for CURL,
Sudo apt-get install php-curl
Oops, don’t forget to add SUDO before that command


Now run this command
“composer require, then name of library”
means “composer require  magium/active-directory”

You may see some problems like this, because there are many extension that may require for that JSON to run.
In simple words, currently we installed “php-curl”, which is one of the extension we needed.

You can paste those problems below in comment box, I shall try to find the solution to those problem. Most of the time, the problem could be the “mission extensions” in your system.
You can ignore this orange thing.
Now if you look inside program, there is a vendor folder which was generated by execute composer.json file.
Now we have to compress that file in ZIP only and upload it in LIVE WEBSITE using CPANEL, you can also you upload a whole folder via FTP, so that you don’t have to compress folder.(FTP takes more time to upload)
You will have to upload that zip file in public_html.
Once uploaded, go to file system, and extract that zip file.
Your folder will appear, now go inside that folder, then example, then the www.
Edit the index.php.
Add comma here.
HERE, have to add  new array key as ‘redirect_url’.
Add client ID, client secret, directory as common.

I made a mistake here, type “return_url” as a “key”.

Now, lets test it,  paste our link in browser’s URL.
You will be automatically redirected to Microsoft LOGIN.
Which means, that index.php file can be used as a login page for your web application.
You see that, they provide you some info about user, you can user’s email and name in PHP session  to maintain login and to create account.
Share it with your colleagues, friends, or employees to implement Microsoft azure authentication in your website.

Required links are given in the description.
Thanks for watching. 
Don’t forget to like, share and subscribe.
-------------------------------------------------------
Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/

Friday, 20 March 2020

Easiest Way To Change Date From One Timezone To Any Another Timezone | PHP And MYSQL | CONVERT_TZ


Code :-
<style type="text/css">
    body {
  font-family: Arial, Helvetica, sans-serif;
}
</style>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'test';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);

if(! $conn ) {
   die('Could not connect: ' . mysqli_error());
}
else
{
    echo "DATABASE CONNECTED<br/>";
}

//CONVERTING TIME FROM NEW YORK(USA) -> KOLKATA(INDIA)
//FROM = NEW YORK
// TO = KOLKATA
$from_exact_date_time='2020-02-15 09:00:00';
$from_timezone=new DateTimeZone('America/New_York');
$from_datetime=new DateTime('now',$from_timezone);
$from_format=$from_datetime->format('P');
echo "New York format : ".$from_format."<br/>";

$to_timezone=new DateTimeZone('Asia/Kolkata');
$to_datetime=new DateTime('now',$to_timezone);
$to_format=$to_datetime->format('P');
echo "Kolkata format : ".$to_format."<br/>";

$query="SELECT CONVERT_TZ('".$from_exact_date_time."','".$from_format."', '".$to_format."') as converted_date";
$data=mysqli_query($conn,$query);

$output=mysqli_fetch_array($data);

echo "NEW YORK DATE/TIME IS : ".$from_exact_date_time."<br/>";
echo "KOLKATA DATE/TIME IS  : ".$output['converted_date'];


?>
</body>
------------------------------------------------
Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------
World Time Buddy :-
https://www.worldtimebuddy.com/

List of timezone : -
https://www.php.net/manual/en/timezones.php

Code Link : -

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------

Hey guys, this is UNPOSSIBLE POG.
In this video, I shall tell you the easiest way to convert date-time from one timezone to any other timezone using PHP and mysql.
In this example I will be converting NEW YORK time to KOLKATA time.
There is a website called “worldtimebuddy” (NOT SPONSORED) which will tell you exact time difference between two timezones.
Link in the description.
I am adding kolkata time and if you click on it, you will see that when in NEW YORK, the date-time is 15th of march 2020 2:00AM, at that time in kolkata, the time is 15th of marth 2020 11:30 AM.
Moving back to code I already added a code of database connection of MYSQLI.
In our code, FROM is NEW YORK and TO is KOLKATA.
First we shall get timezone.
In PHP manual, you will get all the available timezone list. Search for desired timezone.
Then in code, we shall get datetime of that timezone.
It’s link is also given in description.
Then get the difference format.

Same thing we have to do for “TO Timezone” that is, for KOLKATA.
Lets verify.
Remember that those formats are based on UTC.
If you want to convert from UTC then the format is always +00:00.
Then we write an SQL query, there is a function in query called CONVERT_TZ with 3 arguments.
1st argument is the time that you want to convert.
2nd argument is the format of that date, in your case, it is NEW YORK’s format.
3rd argument is the format of timezone that we want to convert.
If everything is correct, then the should be 15 march 2020 : 11:30 AM.
Lets try another date-time.
If in new york the time is 9 AM, then in kolkata it should be 18:30 of same date.
Required links are given in the description.
Thanks for watching. 
Don’t forget to like, share and subscribe.

Saturday, 7 March 2020

Google Sheet API | Part 1 | Linux Only | Connect And Display Sheet Data ...




Download VENDOR Folder (Only for PHP version 7.2+): https://unpossiblepog.com/research-and-development/php/Vendor-Folder-For-Google-Sheet-Drive-Calendar-With-PHP-Version-7.2-And-Onward

Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------
Social Media Links :-

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------

Hey guys, this is UNPOSSIBLE POG.
In this video, I shall tell you how to connect connect xampp PHP with google spreadsheet.
In first part, I shall show you how to display data on browser.
There are few requirements that your should have.
1st is to use linux OS. Most preferable is the operating system from Debian Family.
If you want to know how to install and use PHP in LINUX, then tutorial video’s link is given in description.
Now lets get started, go to google and search google spreasheet api php.
Go inside this link, “developer.google.com"
In latest edition of this link, they improved some steps to make integration easier.
Now it says you require php version more than 5.4.
Go to htdocs location.
Create a new folder.
Change it’s persmission to write inside it.
Open the IDE, and assign the folder in it. I prefer sublime text.
Open it in terminal.
now install composer by using this command.
“sudo apt-get install composer”
As you can see I already installed it.
Go to website and enable your google sheet api credentials.
Download it’s configuration.
Copy-paste it in your new created folder which is in htdocs. in my case its google_sheet.
Now we shall run provided command in folder’s terminal.
It may take more than 1 minute because the command is downloading  composer files from google server which are must to run the API.
Copy paste the code in newly created file.
Make sure to close PHP tag.
Now here, you have to make many changes.
First, remove underscore-readonly text from scope.
Add DIR before those two file locations.
Now, by default, google provided some default spreadsheet link which is common for multiple people but we don’t want that so create a new spreadsheet.
Now copy its id which is after D-slash upto another slash, and paste it in code.
Now each spreadsheet has it’s own name, which is at the left corner.
The name is sheet1, so type it in range variable.
And also column are available from A to C.
Lets first run it in terminal because we are going to create a secret key for security purpose.
Well, I forgot to add slash there.
Lets return it.
Now they provide a link, copy it and paste it in browser’s url.
Login into email ID.
Click on advance then go to quickstart unsafe.
Allow access, and copy paste this code in terminal.
There is another mistake that I have made.
Oh yaa, the sheet name was incorrect. Make sure that you should type sheet’s name before exclaimation sign.
Rerun it.
Umm, the output did come but I think that I was jumping on 5th column but in excel sheet there are only 3 columns so make sure that, you only give column number up to maximum available columns in spreadsheet.
 Now to run this code in browser, just comment those lines and open that page in browser.


Required links are given in the description.
Thanks for watching.
Don’t forget to like, share and subscribe.

Saturday, 15 February 2020

PHP Tutorial | Easiest Way To Sort Date Array | KSORT



Code :-
<?php
$dates_array=array(
    "2020-01-5",
    "2020-01-10",
    "2018-03-4",
    "2019-01-15",
    "2020-01-2",
    "2020-05-3",
    "2020-01-9",
    "2020-02-8"
);

$new_array=array();
for ($i=0; $i < sizeof($dates_array); $i++)
{
    $new_array[ strtotime( $dates_array[$i] ) ]=$dates_array[$i];
}

ksort($new_array);

foreach ($new_array as $key => $value) {
    echo '<div>'.$value.'</div>';
}


?>
The following array is new_array :
<pre>
    <?php print_r($new_array);?>
</pre>

------------------------------------------------
Social Media Links :-

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------

Hey guys, this is UNPOSSIBLE POG.
In this video, I shall  show you the easiest way to sort date-array using PHP language.
As you can see, on left hand side, there is a code. and right hand displays an output in browser.
So there is a basic sort function in PHP which sorts array but only by character and not by dates.
Here., the “2nd january 2020” should be at first position followed by “3rd january 2020”.
So the sort function will not work in this case.
Now, we have to use new array with key-value pairs.
Let’s create a for loop and assign values in new array that we created.
But the code is not enough. What we should do is use strtotime function to convert date into integer. And use that integer as a key rather than 0,1,2,3 etc.
Now lets refresh, and you see each date with key-value pair where key is an integer value of that date.
Now we only have to do is to sort keys.
So there is a function called “ksort”.
If we use that and refresh it, it will sort all data by dates.
Lets try different years.
If you want to use sorted array, then use foreach loop.
The full code is in the description.
Thanks for watching.
Don’t forget to like, share and subscribe.

Monday, 27 January 2020

A Trip To Madhya Pradesh Part 2 | Last Two And Half Days | Narmada And K...




After visiting two main temples in journey, we had a free time to
explore more. We realize that there are way too many temples. The best
part of journey is when we stand in front of huge DAM. That spots
thrilled us. The scary part was that we reached to railway station just 5
minutes before the train leaves. Just caught train in time.