简体   繁体   English

如何检测URL中的GET参数并根据其放置值?

[英]How to detect GET parameters in URL, and place values according to that,?

I am working on a project in PHP and JavaScript, where i have to create a value from my end, and pass the same in URL query string on redirect from my URL, Below is Description: I have a URL, https://abc.amindfad.com/c.php?id= {abdid} 我正在使用PHP和JavaScript开发一个项目,我必须从头创建一个值,并在从我的URL重定向的URL查询字符串中传递相同的值,以下为说明:我有一个URL, https:// abc .amindfad.com / c.php?id = {abdid}

on above URL I want redirection, and pass value from my end by detecting where is {abdid} 在上述URL上,我要重定向,并通过检测{abdid}在哪里传递值

The above URL will be redirecting from (my URL) :- https://console.adcashod.net/click.php 上述网址将从(我的网址)重定向: -https : //console.adcashod.net/click.php

i have not done anything yet, Because i am little confused in Code which should be used here. 我还没有做任何事情,因为我对应该在这里使用的代码有点困惑。

in Results I want that, when I click on (my URL) :- https://console.adcashod.net/click.php 在结果中,当我单击(我的URL)时,我希望这样做: -https : //console.adcashod.net/click.php

it get redirects to :- https://abc.amindfad.com/c.php?id= {abdid} but, 它会重定向到:-https://abc.amindfad.com/c.php ? id = {abdid},但是,

replace {abdid} with a value which is defined by me. 用我定义的值替换{abdid} for it. 为了它。

Waiting for suggestions. 等待建议。

Take a look at this https://www.php.net/manual/en/function.str-replace.php 看看这个https://www.php.net/manual/en/function.str-replace.php

$value = 'value_defined_by_me';
$url = 'https://abc.amindfad.com/c.php?id={abdid}';
$url = str_replace('{abdid}', $value, $url); //output: https://abc.amindfad.com/c.php?id=value_defined_by_me

As in simple 如简单

let url = new URL('https://abc.amindfad.com/c.php?id=value&name=john');

let searchParams = new URLSearchParams(url.search);

console.log(searchParams.get('id'));  // outputs "value"

console.log(searchParams.get('name'));  // outputs "john"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM