# Unable to getUser() after logging into a PHP 7.4 Regular Application with a Subdomain

**URL:** <https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768>\
**Category:** Get Help\
**Tags:** php\
**Created:** [December 14, 2020, 12:14am UTC](https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768 "2020-12-14T00:14:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ymonye](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ymonye/32/12934_2.png) [@ymonye](https://community.auth0.com/u/ymonye)\
**Post date:** [December 14, 2020, 12:14am UTC](https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768/1 "2020-12-14T00:14:40Z")

</div>

Hi all,

I’m currently following the Quickstart PHP guide for setting up Auth0 for my website. Everything is run off an Apache/2.4.6 server with PHP 7.4, and I have a custom domain for my login. All dependencies were installed using `composer require auth0/auth0-php:"~7.0"`

The sample PHP code can be found here:  
[https://github.com/auth0-samples/auth0-php-web-app/tree/master/00-Starter-Seed](https://github.com/auth0-samples/auth0-php-web-app/tree/master/00-Starter-Seed)

I’m able to successfully process both logins and new registrations, and my callback URL points back to my index page. The require statement points to the correct directory for autoload.php, and loads fine. However, my code breaks at the `getUser()` command.

```
require __DIR__. 'vendor/autoload.php';
            
use Auth0\SDK\Auth0;

$auth0 = new Auth0([
'domain' => ' **********',
'client_id' => ' **********',
'client_secret' => ' **********',
'redirect_uri' => ' **********',
'scope' => 'openid profile email',
]);

$userInfo = $auth0->getUser();

if (!$userInfo) {
	// Redirect to the login page
} else {
	// Only show page for logged in users
}

```

I’d love some help, as I haven’t any idea why that’s failing on my end. I ran a search across the forum and most users with a similar issue had Safari issues, whereas mine breaks on most browsers.

> [@getUser fails immediately after login](https://community.auth0.com/t/getuser-fails-immediately-after-login/31243):
>
> When a user logs-in via the loginWithRedirect() method of auth0-spa-js, and returns to the callback URL, handleRedirectCallback() is processed successfully, but subsequent calls to getUser() return undefined and isAuthenticated() returns false. The Auth0 Hosted Logs show an error entitled “Failed Silent Auth”: { "date": "2019-09-22T18:54:07.091Z", "type": "fsa", "description": "Login required", "client\_id": "...", "client\_name": "...", "ip": "...", "user\_agent": "Safari 13.0.1 / M…

Thanks,  
Nick

---

<div class="post-metadata">

**Author:** ![ymonye](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ymonye/32/12934_2.png) [@ymonye](https://community.auth0.com/u/ymonye)\
**Post date:** [December 14, 2020, 1:05am UTC](https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768/2 "2020-12-14T01:05:33Z")

</div>

=====EDIT=====

Looks like this problem only occurs when using subdomains on my site, especially when used as my redirect. For example, the below configuration works as intended:

Custom Domain: [https://auth.example.com](https://auth.example.com)  
Login Page: [https://example.com/login.php](https://example.com/login.php)  
Redirect Page: [https://example.com/explore/app/index.php](https://example.com/explore/app/index.php)  
  
  
In my scenario, I’m using my /explore/ folder as a subdomain, and a .htaccess rewrite to advance in the /explore/ folder when viewing the subdomain page, so that it doesn’t appear in my URL. Here’s how it looks behind the scenes:

[https://example.com/explore/app/index.php](https://example.com/explore/app/index.php) =\> [https://explore.example.com/app/index.php](https://explore.example.com/app/index.php)

```
RewriteEngine On
RewriteCond %{HTTP_HOST} ^explore\.example\.com$
RewriteCond %{REQUEST_URI} !^/explore/
RewriteRule (.*) /explore/$1

```

  
With this setup, I have the following:

Custom Domain: [https://auth.example.com](https://auth.example.com)  
Login Page: [https://example.com/login.php](https://example.com/login.php)  
Redirect Page: [https://explore.example.com/app/index.php](https://explore.example.com/app/index.php)

Apparently Auth0 fails to recognize the user session when using a subdomain. Is there anything I can do for the subdomain to recognize that session? At this point I’m not sure if that’d imply an additional .htaccess rule or PHP / JS modification. I do however have [https://explore.example.com/app/](https://explore.example.com/app/) as an allowed callback URL & logout URL under my application settings.

---

<div class="post-metadata">

**Author:** ![ymonye](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ymonye/32/12934_2.png) [@ymonye](https://community.auth0.com/u/ymonye)\
**Post date:** [December 14, 2020, 3:50pm UTC](https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768/3 "2020-12-14T15:50:18Z")

</div>

Even more updates (sorry for the triple post).

It seems even after removing the .htaccess rule and eliminating that variable, redirects using a “www” subdomain fail as well, whereas [https://example.com/explore/app/](https://example.com/explore/app/) redirects (without any subdomain) work without issue. So let’s work with the www subdomain for now.

I’d added a wildcard to my Allowed Callback & Logout URLs under my Application settings page (https://\*.example.com/explore/app/), then added [https://www.example.com/explore/app/](https://www.example.com/explore/app/) to `'redirect_uri'` in my index.php & login.php PHP files, yet still have no luck reading the getUser() info. To reiterate, these pages work fine without any sort of subdomain ([explore.example.com](http://explore.example.com) or [www.example.com](http://www.example.com)).

Might I add that I also have the [example.com](http://example.com) A name, as well as the “www” and “explore” CNAMEs proxied through Cloudflare. I’d temporarily changed the Proxy status to DNS only, yet still unable to read while using the www subdomain on my page. My Auth0 custom login domain however works fine under Cloudflare when added as a CNAME with proxy disabled (DNS only).

---

<div class="post-metadata">

**Author:** ![ymonye](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ymonye/32/12934_2.png) [@ymonye](https://community.auth0.com/u/ymonye)\
**Post date:** [December 16, 2020, 9:23pm UTC](https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768/4 "2020-12-16T21:23:12Z")

</div>

Hey all,

It looks like I was able to resolve this issue after working with the support team. I’d noticed if I accessed my login.php page from the same subdomain as my web page, by adding ‘www’, I was then able to access my main site also on the ‘www’ subdomain. Now moving my login.php file to the ‘explore’ subdomain worked as well.

So in summary, my Application Login URL has to be on the same subdomain as my main site. All works fine now! Marking this as the solution if anyone else stumbles across this in the future.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2020, 10:41am UTC](https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768/5 "2020-12-17T10:41:03Z")

</div>

Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 1, 2021, 10:41am UTC](https://community.auth0.com/t/unable-to-getuser-after-logging-into-a-php-7-4-regular-application-with-a-subdomain/54768/6 "2021-01-01T10:41:04Z")

</div>

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