How to use $_GET in your included files
I'm used to doing just <c:import url="/viewaccount.do?id=${account.accountId}"/> in JSP. So when I was asked to make a simple PHP script I thought the same thing was possible in PHP using the include() command. I was wrong though and thought of using session globals as a workaround. It's a good thing that I searched the internet first for a more elegant solution.
What I needed was for the $_GET["id"] variable to be visible in one of my included file. The solution? It's a basic one, really. Just create a function that accepts the id as an argument
1 2 3 4 | function showAccount($accountId) { //some complicated stuff here...
return; } |
And suppose the function above is in a file called functions.php. Just include it your code and make a call to showAccount like this
1 | showAccount($_GET["id"]); |
I wish I was doing Java instead of PHP though... [SIGH]