How to pass parameters with `include`?

前端 未结 6 1361
醉梦人生
醉梦人生 2021-02-15 16:50

I have a PHP script called customers.php that is passed a parameter via the URL, e.g.:

http://www.mysite,com/customers.php?employeeId=1

Inside my customers.php s

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-15 17:31

    PHP includes are really includes; they attach piece of code from that location to this location.

    PaulPRO’s answer most likely tells what you want to achieve, but also other variables would be usable in the included file. So if you define $foo = "bar"; in index.php and include layout.php after that line, you could call this $foo variable in that layout.php file.

    If you seriously want to pass an URL to the file, you can insert the URL into variable and in included file parse it with parse_url

    EDIT: and yes, I do not suggest adding query params to actual include url as it starts to mess up with GET array and eventually you’ll just be confused what there should be and start smacking your head into wall.

提交回复
热议问题