-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.php
More file actions
32 lines (26 loc) · 1.26 KB
/
index.php
File metadata and controls
32 lines (26 loc) · 1.26 KB
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
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include('lib/shopify_api.php');
if (!defined('API_KEY') || !defined('SECRET') || isEmpty(API_KEY) || isEmpty(SECRET)) die('Both constants API_KEY and SECRET must be defined in the config file.');
/* GET VARIABLES */
$url = (isset($_GET['shop'])) ? mysql_escape_string($_GET['shop']) : '';
$token = (isset($_GET['t'])) ? mysql_escape_string($_GET['t']) : '';
$timestamp = (isset($_GET['timestamp'])) ? mysql_escape_string($_GET['timestamp']) : '';
$signature = (isset($_GET['signature'])) ? mysql_escape_string($_GET['signature']) : '';
$params = array('timestamp' => $timestamp, 'signature' => $signature);
/*
Step 1:
Create a new Shopify API object with the $url, $token, $api_key, and $secret, and [$params]
You must first ping the shop auth URL if you have not. You can do this by using Session::create_permission_url()
Your application's Return URL will then be pinged with the shop, token, signature and timestamp.
After this authorization is done you can then make requests to the API.
*/
$api = new Session($url, $token, API_KEY, SECRET);
//if the Shopify connection is valid
if ($api->valid()){
if (isEmpty($token)){
header("Location: " . $api->create_permission_url());
}
}
?>