Jump to content

help with the function displaying contents of the text file


tomasd

Recommended Posts

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]<?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";
}
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]<?php
function writeMyName()
  {
  echo "Kai Jim Refsnes";
  }writeMyName();
?>[/code]
works OK... so it's something I do wrong
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
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]<?php
global $domain;
$domain = GetHostByName($REMOTE_ADDR);
function showfile()
{
echo $domain;
            echo "IP";
}
showfile();
?>[/code]
I only get the message saying IP on the screen...
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.