How to pass a PHP variable using the URL

后端 未结 6 524
暖寄归人
暖寄归人 2020-11-30 04:20

I want to pass some PHP variables using the URL.

I tried the following code:

link.php





        
6条回答
  •  不知归路
    2020-11-30 04:42

    In your link.php your echo statement must be like this:

    echo 'Link 2';
    

    Then in your pass.php you cannot use $a because it was not initialized with your intended string value.

    You can directly compare it to a string like this:

    if($_GET['link'] == 'Link1')
    

    Another way is to initialize the variable first to the same thing you did with link.php. And, a much better way is to include the $a and $b variables in a single PHP file, then include that in all pages where you are going to use those variables as Tim Cooper mention on his post. You can also include this in a session.

提交回复
热议问题