tomasd Posted December 12, 2006 Share Posted December 12, 2006 Hi,I'm not that good at programming, please forgive me.I'm trying to open a vbs generated file named by the ip address of the pc that it was generated on, using php code:[code]<?php $domain = GetHostByName($REMOTE_ADDR); $filename = "\\\\10.0.0.1\\GroupData\\Public\\IT\\Support\\$domain"; echo "<pre>\n"; @readfile($filename); echo "</pre>\n";?>[/code]Which works just fine.. but when I'm trying to use this as a funtion i.e.:[code]<?phpfunction showfile() { $domain = GetHostByName($REMOTE_ADDR); $filename = "\\\\10.0.0.1\\GroupData\\Public\\IT\\Support\\$domain"; echo "<pre>\n"; @readfile($filename); echo "</pre>\n"; }showfile();?>[/code]I'm getting blank page checking the page source it comes up with:[code]<pre></pre>[/code]I'm not sure where the problem is... can somebody please point me to the right direction?Script from [url=http://www.w3schools.com/php/php_functions.asp]http://www.w3schools.com/php/php_functions.asp[/url][code]<?phpfunction writeMyName() { echo "Kai Jim Refsnes"; }writeMyName();?>[/code]works OK... so it's something I do wrong Link to comment https://forums.phpfreaks.com/topic/30353-help-with-the-function-displaying-contents-of-the-text-file/ Share on other sites More sharing options...
utexas_pjm Posted December 12, 2006 Share Posted December 12, 2006 remove the '@' from @readfile(); The '@' is supressing any error or warning the function might be throwing. Then run the script again. Link to comment https://forums.phpfreaks.com/topic/30353-help-with-the-function-displaying-contents-of-the-text-file/#findComment-139661 Share on other sites More sharing options...
tomasd Posted December 12, 2006 Author Share Posted December 12, 2006 Hi, Thanks for reply, I've removed @ from both scripts (let's call it A with no function and B with the function)on A script I've got the same output as usual (the contents of the file) running B script I've got an error:Warning: readfile(\\10.0.0.1\GroupData\Public\IT\Support\10.176.40.31): failed to open stream: No such file or directory in c:\web\devel\fopen\b.php on line 7 Link to comment https://forums.phpfreaks.com/topic/30353-help-with-the-function-displaying-contents-of-the-text-file/#findComment-139702 Share on other sites More sharing options...
tomasd Posted December 12, 2006 Author Share Posted December 12, 2006 I found that [code]<?php function showfile() { $domain = GetHostByName($REMOTE_ADDR); $filename = "\\\\10.0.0.1\\GroupData\\Public\\IT\\Support\\$domain"; echo "<pre>\n"; @readfile($filename); echo "</pre>\n"; }[/code]turns $domain variable to the ip address of the compter that web server is running on, therefore I think I need to assign $domain before the function and to make it accessable it should be global, for some reason if I do[code]<?phpglobal $domain;$domain = GetHostByName($REMOTE_ADDR); function showfile() { echo $domain; echo "IP"; }showfile();?>[/code]I only get the message saying IP on the screen... Link to comment https://forums.phpfreaks.com/topic/30353-help-with-the-function-displaying-contents-of-the-text-file/#findComment-139720 Share on other sites More sharing options...
tomasd Posted December 12, 2006 Author Share Posted December 12, 2006 the "correct" code[code]<?php$domain = GetHostByName($REMOTE_ADDR); function showfile() { global $domain; $filename = "\\\\10.0.0.1\\GroupData\\Public\\IT\\Support\\$domain"; echo "<pre>\n"; readfile($filename); echo "</pre>\n"; }showfile();?>[/code] Link to comment https://forums.phpfreaks.com/topic/30353-help-with-the-function-displaying-contents-of-the-text-file/#findComment-139733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.