Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

emilpapelas4@gmail.com's avatar

How can i get partner and token value from this link

How can i get partner and token value from this link

https://steamcommunity.com/tradeoffer/new/?partner=126763931&token=DUROP2Q9

0 likes
32 replies
Sinnbeck's avatar

I assume that the url is a request to your website? (if not, give us some more information)

public function index(Request $request)
{
    $partner = $request->input('partner');
    $token = $request->input('token');
}
emilpapelas4@gmail.com's avatar

@Sinnbeck

This example that u sent not works.

public function checkout(Request $request)
    {
        if(Auth::user()->trade_url = "")
        {
            Flashy::error("Trade Url Missing from your Profile.");
        }
        else
        {
            $trade = Auth::user()->trade_url;

            $partner = explode('&',explode("partner=",$trade)[1])[0];
            $token = explode("token=",explode('&',explode("partner=",$trade)[1])[1])[1];

        dd($partner);
        }
}

First i check if user have added an trade url on their profile if yes may proceed next to get the value of this 2 parameters but not works.

tykus's avatar

If this is not a URL into your application, and you simply want to get the query params:

parse_str(
    parse_url($url, PHP_URL_QUERY),
    $params
);
dd($params);
emilpapelas4@gmail.com's avatar

@tykus

as result want to get as following

$partner = 126763931

$token = DUROP2Q9

because later will use this 2 params on a link to make a buy request and need this 2 params to work.

Sinnbeck's avatar

@emilpapelas4@gmail.com Post the output of this please :)

 $trade = Auth::user()->trade_url;

            $params = [];
            parse_str(
                parse_url($trade, PHP_URL_QUERY),
                $params
            );
            dd($trade, $params);
tykus's avatar

@emilpapelas4@gmail.com are you sure that is the authenticated user (is it the only User in the database table)? Do you have any accessor for the trade_url property on the User model?

Sinnbeck's avatar

@emilpapelas4@gmail.com It is because you are setting it to an empty sting. = means assign. == or === means compare

 if(Auth::user()->trade_url === "") //fixed
1 like
emilpapelas4@gmail.com's avatar

@tykus about tomorrow issues with {{$items->links()}}

maybe can u go on that thread and find an help for me?

tykus's avatar

@emilpapelas4@gmail.com so your checkout method could look like this

function checkout(Request $request)
{
  $trade = Auth::user()->trade_url;

  if (! $trade) {
    Flashy::error("Trade Url Missing from your Profile.");
  } else {
    parse_str(parse_url($trade, PHP_URL_QUERY), $params);
    extract($params); // $partner and $token are in scope now
  }
  // .... something more?
}

about tomorrow issues with {{$items->links()}}

I thought that was solved?

lat4732's avatar
lat4732
Best Answer
Level 12

@emilpapelas4@gmail.com As it's not a URL from your website, you can do this

$URL = 'https://steamcommunity.com/tradeoffer/new/?partner=126763931&token=DUROP2Q9';

$parse = parse_url($URL);
$explode = explode('&', $parse['query']);

print_r($explode);

And the result is

[
      [0] => partner=126763931
      [1] => token=DUROP2Q9 
] 

And if you want to retrieve only the values you can str_replace

$URL = 'https://steamcommunity.com/tradeoffer/new/?partner=126763931&token=DUROP2Q9';

$parse = parse_url($URL);
$explode = explode('&', $parse['query']);

$partner = str_replace('partner=', '', $explode[0]);
$token = str_replace('token=', '', $explode[1]);

and the result of this will be

$partner = 126763931;
$token = "DUROP2Q9";

Please or to participate in this conversation.