How can I dynamically retrieve a store name in a core PHP Shopify app?

How can I dynamically retrieve a store name in a core PHP Shopify app?

mayurshrimali
Shopify Partner
2 0 0

Dear Support,

I trust this message finds you well.

I have successfully developed a Shopify app using core PHP. However, I am encountering an issue while running the install.php file—I am unable to retrieve the Shopify shop name.

Here is the code snippet I am currently using:

<?php

$dotenv = parse_ini_file('.env');

$shop = $_GET['shop'];
$api_key = $dotenv['API_KEY'];
$scopes = "read_orders,write_products,read_themes,write_themes";
$redirect_uri = $dotenv['REDIRECT_URI'];

// Build install/approval URL to redirect to
$install_url = "https://" . $shop . ".myshopify.com/admin/oauth/authorize?client_id=" . $api_key . "&scope=" . $scopes . "&redirect_uri=" . urlencode($redirect_uri);

// Redirect
header("Location: " . $install_url);
die();

While manually adding the shop name statically functions as expected, I am seeking guidance on dynamically obtaining the shop name. Could you kindly advise me on the appropriate approach to achieve this?

Thank you for your assistance.

Replies 0 (0)