# Login php sul mio sito web

**URL:** <https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081>\
**Category:** API\
**Created:** [November 14, 2020, 10:06am UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081 "2020-11-14T10:06:34Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 15, 2020, 12:43pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/21 "2020-11-15T12:43:18Z")

</div>

more simply I just have that subscribers can access non-subscribers are reported to the index with an error message

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 15, 2020, 12:51pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/22 "2020-11-15T12:51:07Z")

</div>

Pardon? Not sure what you mean here

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 15, 2020, 12:53pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/23 "2020-11-15T12:53:31Z")

</div>

I mean that, before I wanted each subscription level to have a page, now it is enough that each subscriber can enter the same page regardless of the subscription level, then non-subscribers are reported to the index to receive an error message saying they are not subscribers .

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 15, 2020, 12:55pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/24 "2020-11-15T12:55:37Z")

</div>

So it’s working then?

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 15, 2020, 12:56pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/25 "2020-11-15T12:56:06Z")

</div>

no, I was wondering if he could get this thing into my code

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 15, 2020, 12:57pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/26 "2020-11-15T12:57:39Z")

</div>

you already have all the parts you need you just need to write the if statements and flow to match your needed conditions

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 15, 2020, 12:58pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/27 "2020-11-15T12:58:55Z")

</div>

what is the scope to check if the user is a subscriber?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 15, 2020, 1:06pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/28 "2020-11-15T13:06:11Z")

</div>

as documented in the docs I linked earlier

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

it’s `channel:read:subscriptions`

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 15, 2020, 1:13pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/29 "2020-11-15T13:13:33Z")

</div>

```auto
<?php

$client_id = '';
$client_secret = '';
$redirect_uri = '';

if (isset($_GET['code']) && $_GET['code']) {
    $token_url = "https://id.twitch.tv/oauth2/token";
    $data = array(
        'client_id' => $client_id,
        'client_secret' => $client_secret,
        'grant_type' => 'authorization_code',
        'redirect_uri' => $redirect_uri,
        'code' => $_GET['code']
    );

    $curl = curl_init($token_url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 1000);

    $result = curl_exec($curl);
    $i = curl_getinfo($curl);
    curl_close($curl);

    if ($i['http_code'] == 200) {
        $result = json_decode($result, true);

        $curl = curl_init('https://api.twitch.tv/helix/user');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Client-ID: ' . $client_id,
            'Authorization: Bearer ' . $result['access_token']
        ));
        curl_setopt($curl, CURLOPT_TIMEOUT, 1000);

        $user = curl_exec($curl);
        $i = curl_getinfo($curl);
        curl_close($curl);

        if ($i['http_code'] == 200) {
            $user = json_decode($user);

            echo '<p>Thanks ' . $user->display_name . ' <3</p>';
        } else {
            echo '<p>An error occured, please <a href="/index.php">click here and try again</a></p>';
        }
    } else {
        echo '<p>An error occured, please <a href="/index.php">click here and try again</a></p>';
    }
} else {
    $auth_url = 'https://api.twitch.tv/kraken/oauth2/authorize?response_type=code';
    $auth_url .= '&client_id=' . $client_id;
    $auth_url .= '&redirect_uri=' . $redirect_uri;
    $auth_url .= '&scope=channel:read:subscriptions';
    $auth_url .= '&force_verify=true';

    echo '<a href="' . $auth_url . '">Please Click this Link to Authenticate with Twitch</a>';
} elseif{
    $auth_url . = false{
        header("Location: index.php");
        echo = "you are not a subscriber";
    }
}

```

would this last part work?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 15, 2020, 1:17pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/30 "2020-11-15T13:17:12Z")

</div>

No, it’s syntax is wrong, you go if, else, else if

and the elseif has no clause

That’s seems to be an oAuth loop to get a token with `channel:read:subscriptions`

`echo = "you are not a subscriber";` suggests you are trying to do a subscriber check here, but this is just a loop to get the authentication/permission from the broadcaster

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 15, 2020, 1:19pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/31 "2020-11-15T13:19:09Z")

</div>

excuse me, i know i’m stressing you, can you try in no hurry to modify the code and add the new parts to check it? Please! 🙂

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 16, 2020, 3:10pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/32 "2020-11-16T15:10:18Z")

</div>

hi, i’m indebted to a job on this, could someone fix my script with subscriber control? Thanks!!

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 16, 2020, 3:17pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/33 "2020-11-16T15:17:45Z")

</div>

You’ve been given the relevant information, samples and explanation on how the flow.

We cannot do all your work for you.

Get and store a key from the broadcaster with the `channel:read:subscriptions` and refresh said key as needed

Then a regular user will Login to your website  
Then use the broadcasters key with the logged in user ID against the broadcaster subscriptions API to check status

It’s not a single script, it’s two web pages/flows and a cronjob to maintain the broadcasters key.

You can even modify the user authentication script I already gave you to get the broadcasters key, you just need to determine where you want to store the broadcasters key for reuse

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [November 19, 2020, 6:38pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/34 "2020-11-19T18:38:48Z")

</div>

hello I ask with all my heart, could someone make my request work? i can’t it’s since my last post i try day and night to make it work but i can’t, thanks in advance.

---

<div class="post-metadata">

**Author:** ![frgofficial](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/frgofficial/32/10692_2.png) [@frgofficial](https://discuss.dev.twitch.com/u/frgofficial)\
**Post date:** [December 4, 2020, 4:54pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/35 "2020-12-04T16:54:35Z")

</div>

Hey guys so could someone provide me with the missed scripts to complete my project, I know it’s annoying but for a good cause.

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [January 3, 2021, 4:54pm UTC](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081/36 "2021-01-03T16:54:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[Previous page](https://discuss.dev.twitch.com/t/login-php-sul-mio-sito-web/29081.md?page=1)
