homepage Welcome to WebmasterWorld Guest from 54.205.207.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
passthru()
Exact usage
Knowles

10+ Year Member



 
Msg#: 412 posted 2:25 pm on May 2, 2002 (gmt 0)

I am trying to use the passthru() command in PHP to view an log through a website. But I am having trouble understanding how to set it up. Should it be passthru(log.log); and it just outputs cause thats not working for me. Any suggestions?

 

toadhall

10+ Year Member



 
Msg#: 412 posted 7:00 pm on May 2, 2002 (gmt 0)

If that's the name of your log file and that's the complete path then:

passthru("log.log");

...should do it.

There may be a server permissions issue if you're on a virtual host.

I've never used this function so I'm (almost) only guessing. ;o)

scotty

10+ Year Member



 
Msg#: 412 posted 11:16 pm on May 2, 2002 (gmt 0)

Actually, passthru() takes a program as argument, execute it (through shell??), and then display the raw output. You can read the on-line manual reference here [php.net]. Therefore, you can read a local file using passthru() this way:


<?php passthru('cat log.log'); ?>

Not very clean because it assumes that you are on a Un*x system, because of the requirement of the 'cat' command. Moreover, it does not escape HTML entities so that it might mess up the output. It might be better to open the file, read the content, buffer it, escape the HTML entities, and then send it display. For example,


<?php

$fd = fopen('log.log', 'r');
while (!feof($fd)) {
$buf = fgets($fd, 4096);
echo htmlspecialchars($buf);
}
fclose ($fd);

?>

ggrot

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 412 posted 11:42 pm on May 2, 2002 (gmt 0)

Use fpassthru. It takes a file descriptor as an argument, so it would look like this:

<?php
$fp=fopen("log.log","w");
fpassthru($fp);
?>

scotty

10+ Year Member



 
Msg#: 412 posted 12:30 am on May 3, 2002 (gmt 0)

Yes. fpassthru() is fine as well, and you can also use readfile() function.

<?php readfile("log.log"); ?>

Which is even easier! Except it does not mix with HTML. So I have to buffer it first, run through htmlspecialchars() to escape some characters, and then send to the output.

Knowles

10+ Year Member



 
Msg#: 412 posted 1:06 pm on May 3, 2002 (gmt 0)

The passthru() still would not work I did get it to work with the fopen but it does not format it at all it just runs one long line. Which makes it a little hard to read. I will try the readfile tonight to see if thats possible. Someone mentioned earlier that passthru() could be used for shell scripts? Would that just be passthru("/schell.sh")?

toadhall

10+ Year Member



 
Msg#: 412 posted 4:40 pm on May 3, 2002 (gmt 0)

Try this:

<?
$arrLog = file("log.log");
$countLog = count($arrLog);
for($i=0; $i<$countLog; $i++){
$Log = stripslashes($arrLog[$i]);
echo ("<br>$Log");
}
?>

Knowles

10+ Year Member



 
Msg#: 412 posted 5:51 pm on May 3, 2002 (gmt 0)

Ty for the suggestion I will try that as well when I get home. I may not be able to say if I got it to work till monday since my email is down so I cant retrieve the pw for board and I killed my cookies at the house.

Knowles

10+ Year Member



 
Msg#: 412 posted 3:02 pm on May 4, 2002 (gmt 0)

That worked perfectly ty very much toadhall. Yall saved me maybe now I can get the rest of the site in order.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved