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
You can pass the value through Session
Like
<?php
$_SESSION['name']='peter';
$_SESSION['age']=28;
$_SESSION['name']='Peter';
include('person_info.php');
?>
In person_info.php, start the session and put all session value in the variable and unset the session.
Your include file will have access to the GET variables directly.
You can't add a query string (Something like ?x=yyy&vv=www) onto an include like that. Fortunately your includes have access to all the variables before them, so if $_GET['employeeId']
is defined before you call:
include 'customers.php';
Then customers.php will also have access to $_GET['employeeId'];
This is not so clean but this will work if you need to enter a static parameter:
if (true){
echo "<meta http-equiv='refresh' content='0;url=query_source.php?random=red%20bull' />";
}
else
{
echo "<meta http-equiv='refresh' content='0;url=query_source.php?random=blue%20bull' />";
}
Just put it within your source code for the page which calls the query_source.php.
Once again, it is NOT very clean...
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.
You can use $GLOBALS
to solve this issue as well.
$tit = "Hello";
$GLOBALS["docTitle"] = $tit;
include ("my.php");