# Php parameter passing

**URL:** <https://community.auth0.com/t/php-parameter-passing/41367>\
**Category:** Get Help\
**Created:** [April 19, 2020, 5:28pm UTC](https://community.auth0.com/t/php-parameter-passing/41367 "2020-04-19T17:28:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![edwardsmarkff](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edwardsmarkff/32/12776_2.png) [@edwardsmarkff](https://community.auth0.com/u/edwardsmarkff)\
**Post date:** [April 19, 2020, 5:28pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/1 "2020-04-19T17:28:41Z")

</div>

hello -

maybe this is commonplace, but i never saw this documented anywhere. it appears that we are indeed allowed to include parameters in our `redirect_uri` value. i had expected a nasty message about how the `redirect_uri` does not match or something like that.

in other words, in my `redirect_uri` i am able to append something like `?myValue=auth0Rocks` and it comes through just fine upon successful login

this is very good news! i am almost surprised this works, but very glad it does.😁😁

my question: is this the best way to pass a parameter?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 21, 2020, 9:14pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/3 "2020-04-21T21:14:43Z")

</div>

Hi @edwardsmarkff,

We advise using a state parameter to look up and restore the previous state of the application.

> **[Redirect Users](https://auth0.com/docs/authenticate/login/redirect-users-after-login)**
>
> Describes how to redirect users to URLs that have not been added to the AllowList.

Does that make sense?  
Dan

---

<div class="post-metadata">

**Author:** ![edwardsmarkff](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edwardsmarkff/32/12776_2.png) [@edwardsmarkff](https://community.auth0.com/u/edwardsmarkff)\
**Post date:** [April 23, 2020, 10:17pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/4 "2020-04-23T22:17:48Z")

</div>

this did not work:

```
$auth0 = new Auth0( [ 'domain' => constant('Auth0_domain')
                        , 'client_id' => constant('Auth0_client_id')
                        , 'client_secret' => constant('Auth0_client_secret')
                        , 'redirect_uri' => constant('redirectUrl') //. '?one=twooo'
                        , 'scope' => 'openid profile email name nickname picture'
                        , 'state' => ['oneee' => 'twooooooo']
                        ]
                );

```

and i am not sure how to create a `nonce` using php.

i would like to pay somebody to put a working PHP example together for me of parameter passing, and then have auth0 include the example in their documentation.

parameter passing would be very useful.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 24, 2020, 8:20pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/5 "2020-04-24T20:20:44Z")

</div>

Hi @edwardsmarkff,

Here is our partners page, it lists our partners network where you can find Auth0 contractors.

> **[Partners - Auth0](https://auth0.com/partners)**
>
> Grow your business in an increasingly developer-centric world of apps.

To help with your question, the nonce is basically just a random number, you send it as the state param in your auth request, and when it is returned you can pick up with that user where you left off.

---

<div class="post-metadata">

**Author:** ![ashu4code](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ashu4code/32/20850_2.png) [@ashu4code](https://community.auth0.com/u/ashu4code)\
**Post date:** [May 8, 2020, 3:56pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/6 "2020-05-08T15:56:08Z")

</div>

```auto
autth0( [ 'domain' => constant('Auth0_domain')
                        , 'client_id' => constant('Auth0_client_id')
                        , 'client_secret' => constant('Auth0_client_secret')
                        , 'redirect_uri' => constant('redirectUrl') //. No param pass here
                        , 'scope' => 'openid profile email name nickname picture'
     ]

$state = "myValue=auth0Rocks "
       
        $auth0->login($state,null,$additionalParams);    

after successfull login .
$state = !empty($_GET["state"]) ? $_GET["state"] : null; from url
this $state = "myValue=auth0Rocks "

```

---

<div class="post-metadata">

**Author:** ![edwardsmarkff](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edwardsmarkff/32/12776_2.png) [@edwardsmarkff](https://community.auth0.com/u/edwardsmarkff)\
**Post date:** [May 8, 2020, 4:31pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/7 "2020-05-08T16:31:24Z")

</div>

> [@dan.woda](#):
>
> We advise using a state parameter to look up and restore the previous state of the application.

dan - ashu4code is the contractor i hired to figure this out for me. would it be possible to have this example included in the documentation? i am sure this is easy for most PHP people, but i do not work with PHP very often, so it was very difficult for me.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 8, 2020, 10:10pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/8 "2020-05-08T22:10:59Z")

</div>

Thanks for sharing! We really appreciate it. I will pass the recommendation on to the team. For now, I will mark it as the solution in this thread. Community threads like this often act as a guide for users in similar situations. Thanks!

---

<div class="post-metadata">

**Author:** ![edwardsmarkff](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edwardsmarkff/32/12776_2.png) [@edwardsmarkff](https://community.auth0.com/u/edwardsmarkff)\
**Post date:** [May 13, 2020, 1:03am UTC](https://community.auth0.com/t/php-parameter-passing/41367/9 "2020-05-13T01:03:00Z")

</div>

here is the working example. note that this REALLY needs to be included in a PHP cookbook recipe. note its really pretty simple, but i have not worked with PHP enough recently to have figured this out quickly:

```auto
<?php

// written by ashu4code

$parmArray = [ 'Parm1' => 'One'
                , 'Parm2' => 'Two'
                , 'ServerTime' => date('Y-m-d H:i:s')
                ];

$state = !empty($_GET["state"]) ? $_GET["state"] : null;
                          // ?? required?? $code = !empty($_GET["code"]) ? $_GET["code"] : null;

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

define('redirectUrl' , ( $_SERVER['HTTPS'] ? 'https' : 'http' )
                                        . '://'
                                        . $_SERVER['HTTP_HOST']
                                        . $_SERVER['SCRIPT_NAME']
                                );

$auth0 = new Auth0([
  'domain' => 'dev-2a5XXX8.auth0.com',
  'client_id' => 'kZvXXXXXXXC',
  'client_secret' => '4pXXXXW0',
  'redirect_uri' => constant('redirectUrl'),
  'scope' => 'openid profile email',
]);

$userInfo = null;
try {
        $userInfo = $auth0->getUser();
} catch (Exception $e) {
        $auth0->logout();
        error_log( 'Line: ' . __LINE__. ' -- Caught Auth0 exception: ' . $e->getMessage() . ' -- exiting program.' . "\n" );
        header('Location: ?logout=1' ) ;
        exit;
}

if (!$userInfo) {
    // We have no user info
    // pass the param in $state variable 
        $state = http_build_query($parmArray);
        $auth0->login($state, null, []);
        exit;
} else {
    // User is authenticated
        $userInfo = $auth0->getUser();
        printf( 'Hello %s!', htmlspecialchars( $userInfo['name'] ) ); 

                // display the parameters
        $get_string = $state;
        echo '<br />Result:<br />';
        parse_str($get_string, $get_array);
        echo $get_string;
        echo '<br />';
        print_r($get_array);
        echo '<br />';

        phpinfo(); // or just look here for the parameters
   
}
```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 14, 2020, 4:20pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/10 "2020-05-14T16:20:01Z")

</div>

Thanks for sharing this @edwardsmarkff.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 29, 2020, 4:20pm UTC](https://community.auth0.com/t/php-parameter-passing/41367/11 "2020-05-29T16:20:04Z")

</div>

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