e1seix Posted August 23, 2008 Share Posted August 23, 2008 Problem... and hopefully an easy one to solve with someone's help. My page in question is "video.php" from whose address bar i use $vidID=$_GET['vidID']; to obtain the vidID variable. Now, within my page i use quite a few of echo file_get_contents to break down my website and make it easier to design and manage. From "video.php" i use echo file_get_contents to load "screen.php" My problem is that I need to be able to use the $vidID variable WITHIN screen.php, but the information doesn't seem to work... how can i invisibly transport the value of $vidID into screen.php? Many thanks in advance my favourite people! Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/ Share on other sites More sharing options...
JasonLewis Posted August 23, 2008 Share Posted August 23, 2008 Are you thinking of including files? Or do you want to load their contents? Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623454 Share on other sites More sharing options...
e1seix Posted August 23, 2008 Author Share Posted August 23, 2008 load the file and its code in it's entirety Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623456 Share on other sites More sharing options...
MasterACE14 Posted August 23, 2008 Share Posted August 23, 2008 <?php include("file.php"); // includes the file file_get_contents("file.php"); // grabs the file ?> Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623457 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 Including the file is the way to go and you'll retain variable scope within the included file. Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623458 Share on other sites More sharing options...
e1seix Posted August 23, 2008 Author Share Posted August 23, 2008 isn't including the file getting phased out? stupid question, but can I ask... what is the sodding difference between the two? lol. I always get confused and play about until one or the other works the way I want it to Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623462 Share on other sites More sharing options...
DarkWater Posted August 23, 2008 Share Posted August 23, 2008 *facepalm* When you use file_get_contents() and pass it a filesystem filename rather than a URL, it just reads the file. If you pass it a full URL so PHP uses its file wrapper, you get the output of the script. include actually executes a file on the filesystem and incorporates it into the current script. Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623466 Share on other sites More sharing options...
JasonLewis Posted August 23, 2008 Share Posted August 23, 2008 Did you read the link that I posted? The manual is a great place to read up on these things. Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623471 Share on other sites More sharing options...
e1seix Posted August 23, 2008 Author Share Posted August 23, 2008 a-ha... so how do we explain the error message? Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/e1seix/public_html/advice/video.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623473 Share on other sites More sharing options...
DarkWater Posted August 23, 2008 Share Posted August 23, 2008 Use the filename on the filesystem and NOT the URL. include('foo.php'); <- Right include('http://www.example.com/foo.php'); <- Wrong Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623477 Share on other sites More sharing options...
e1seix Posted August 23, 2008 Author Share Posted August 23, 2008 it is actually beginning to sink in, and i am grateful for having patience to explain it to me. Having one last error though... the url of the page in question is "...co.uk/advice/video.php" and the one i'm trying to include is "...co.uk/contents/screen.php" they're no hierarchy, they're in completely different folders. shouldn't the follwing be working so? video.php contains... echo include("/contents/screen.php"); cos now i'm getting Warning: include(/contents/screen.php) [function.include]: failed to open stream: No such file or directory in /home/e1seix/public_html/advice/video.php on line 16 Warning: include() [function.include]: Failed opening '/contents/screen.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/e1seix/public_html/advice/video.php on line 16 in my defence, it's late for me. lol Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623498 Share on other sites More sharing options...
DarkWater Posted August 23, 2008 Share Posted August 23, 2008 You cannot echo an include, by the way. Just include(), with no echo. include('../contents/screen.php'); P.S: For anyone who wants to correct me, I know that you CAN echo an include() if it returns something, but that's not the case here and it's not all too common anyway. Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623500 Share on other sites More sharing options...
e1seix Posted August 23, 2008 Author Share Posted August 23, 2008 Wasn't too sure about that one, but the exact same error remains even with the echo removed... any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623503 Share on other sites More sharing options...
JasonLewis Posted August 23, 2008 Share Posted August 23, 2008 If you echo an include, if the include was successful it will just echo 1, meaning true. No point really. You need the ../ to go to the directory lower. Look at DarkWaters post carefully. Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623512 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 If you echo an include, if the include was successful it will just echo 1, meaning true. No point really. <?php //file phpfreaks.php echo 'phpfreaks'; ?> <?php //some other file echo include('phpfreaks.php'); //will return: phpfreaks1 ?> Your point is right though, what's the meaning of echoing an included file Quote Link to comment https://forums.phpfreaks.com/topic/120947-solved-echo-file_get_contents-query/#findComment-623517 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.