Welcome to WebmasterWorld Guest from 54.166.224.46

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

passthru()

Exact usage

     
2:25 pm on May 2, 2002 (gmt 0)

10+ Year Member



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?
7:00 pm on May 2, 2002 (gmt 0)

10+ Year Member



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)

11:16 pm on May 2, 2002 (gmt 0)

10+ Year Member



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);

?>

11:42 pm on May 2, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

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

12:30 am on May 3, 2002 (gmt 0)

10+ Year Member



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.

1:06 pm on May 3, 2002 (gmt 0)

10+ Year Member



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")?
4:40 pm on May 3, 2002 (gmt 0)

10+ Year Member



Try this:

<?
$arrLog = file("log.log");
$countLog = count($arrLog);
for($i=0; $i<$countLog; $i++){
$Log = stripslashes($arrLog[$i]);
echo ("<br>$Log");
}
?>
5:51 pm on May 3, 2002 (gmt 0)

10+ Year Member



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.
3:02 pm on May 4, 2002 (gmt 0)

10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month