scbookz Posted August 4, 2009 Share Posted August 4, 2009 what is the best way to get a variable from one file and use it in another file? 1.php has a $yahoo variable 2.php wants to use that variable how do i get that item into 2.php Link to comment https://forums.phpfreaks.com/topic/168734-how-do-you-get-a-variable-from-another-file-how-many-ways-to-do-this/ Share on other sites More sharing options...
scbookz Posted August 4, 2009 Author Share Posted August 4, 2009 page 1 a.php $var = 1 ---------------------------------------------- page 2 b.php echo $var Link to comment https://forums.phpfreaks.com/topic/168734-how-do-you-get-a-variable-from-another-file-how-many-ways-to-do-this/#findComment-890233 Share on other sites More sharing options...
The Little Guy Posted August 4, 2009 Share Posted August 4, 2009 I would do it like this: <?php // 1.php $yahoo = "http://yahoo.com"; ?> <?php // 2.php include '1.php'; echo $yahoo; ?> Link to comment https://forums.phpfreaks.com/topic/168734-how-do-you-get-a-variable-from-another-file-how-many-ways-to-do-this/#findComment-890304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.