如何使用按钮自动复制第1页到第2页上的代码$ _GET

 收藏

how to use duplicate $_GET code?

example: site.com/page1.php?id=123 using the click button to page 2 which id is the same as page1

for example: site.com/page1.php?id=123 use clik button to site.com/page2.php?id=123

I want id 123 automatically follow on page2

回复
  • frem 回复

    You can use http_build_query to generate the page 2 link with the same GET url params in a link.

    This function takes an associtive array (like the $_GET superglobal) and converts it into a query string (like id=123&x=....). So append this to your link like (remember to add a ?):

    $queryParams = http_build_query($_GET);
    
    $pageLink = "page2.php?" . $queryParams;
    
    echo "<a src="$pageLink">Page 2</a>";
    

    然后在您的page2.php文件中,您可以在$ _GET超全局变量中访问它:

    var_dump($_GET);
    

  • 深深小安 回复

    for example like this
    <br><br>
    https://www.youtube.com/watch?v=<b>rg_zwK_sSEY</b>
    <br><br>taken the id back rg_zwK_sSEY to site.com/page1.php?id=rg_zwK_sSEY
    <br><br>then on the code button
    <br><br><button onclick = "location.href = 'othersite.com/page2.php?id=rg_zwK_sSEY'" type = "button"> play now </button>
    
    <br><br>on play now button url, insert link site.com or othersite.com/page2.php?id=rg_zwK_sSEY
    <br><br>id <b>(rg_zwK_sSEY)</b> automatically follow to page2