kwdelre Posted July 4, 2010 Share Posted July 4, 2010 Hey guys, I am defining a variable in my php file that in required in several other pages. How do I include a href link in this variable definition? Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/206724-link-in-php/ Share on other sites More sharing options...
travo1992 Posted July 4, 2010 Share Posted July 4, 2010 Could you please explain a little further? Do you want to send a variable to another page, or do you want the variable available on all pages? Quote Link to comment https://forums.phpfreaks.com/topic/206724-link-in-php/#findComment-1081111 Share on other sites More sharing options...
GetFreaky Posted July 4, 2010 Share Posted July 4, 2010 a.php <?php // Define your global variable function create_global(){ global $variable; $variable = "http://www.google.com"; } ?> b.php <?php include("a.php"); create_global(); print $variable; ?> Is this what you ment? Quote Link to comment https://forums.phpfreaks.com/topic/206724-link-in-php/#findComment-1081113 Share on other sites More sharing options...
Alex Posted July 5, 2010 Share Posted July 5, 2010 @GetFreaky: Why would you do that? You can do just do this: a.php <?php $variable = 'Some value'; b.php <?php include 'a.php'; echo $variable There are almost no cases where you should use the global keyword. As for what the OP wants, I think he's after something like this: $var = '<a href="somefile.php">Link</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/206724-link-in-php/#findComment-1081116 Share on other sites More sharing options...
GetFreaky Posted July 5, 2010 Share Posted July 5, 2010 Ah, strong reading skils on my part. I understand that is a useless method using the "Global" function. Quote Link to comment https://forums.phpfreaks.com/topic/206724-link-in-php/#findComment-1081119 Share on other sites More sharing options...
travo1992 Posted July 5, 2010 Share Posted July 5, 2010 The OP mentioned something about the variable being available in multiple files? Create a file which declares the variable, and simply use include 'file.php'; to declare that variable in all files which require it. Quote Link to comment https://forums.phpfreaks.com/topic/206724-link-in-php/#findComment-1081224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.