Orionsbelter Posted July 12, 2011 Share Posted July 12, 2011 Is there any way too pass variables through include files? i tried to do the following: include"file.php?var1=one"; However this doesn't seem to work is there any way i can pass variables in this way? Link to comment https://forums.phpfreaks.com/topic/241843-is-there-any-way-too-pass-variables-through-include-files/ Share on other sites More sharing options...
btherl Posted July 12, 2011 Share Posted July 12, 2011 You can pass variable like this: $var1 = one; include("file.php"); $var1 will be available inside file.php. If you are using include() with a url instead of a filename, don't do that - you should be using file_get_contents(). In that situation you do need to pass variable a different way, so let me know if you are using urls. Link to comment https://forums.phpfreaks.com/topic/241843-is-there-any-way-too-pass-variables-through-include-files/#findComment-1241978 Share on other sites More sharing options...
premiso Posted July 12, 2011 Share Posted July 12, 2011 To add the btherl's answer. If you have the included file using $_GET already, you can do this: $_GET['var1'] = 'one'; include('file.php'); And not have to change the file.php code. Link to comment https://forums.phpfreaks.com/topic/241843-is-there-any-way-too-pass-variables-through-include-files/#findComment-1241980 Share on other sites More sharing options...
btherl Posted July 12, 2011 Share Posted July 12, 2011 Oops, and I made a typo: $var1 = 'one'; include("file.php"); I had forgotten the quotes around one. Link to comment https://forums.phpfreaks.com/topic/241843-is-there-any-way-too-pass-variables-through-include-files/#findComment-1241993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.