Print this article script help needed

Discussion in 'PHP' started by lasvegascom, Jan 24, 2006.

  1. #1
    I need some help with this print this article script as well. I am linking from my articles pages using this <a href="print.php" class="a_link">Print this Article</a> and I have added the <!-- CONTENT --> and <!-- /CONTENT --> tags to the article pages. But I think I messed the code up below or am missing something somewhere. Can someone please help?

    <?php

    $fd= fread(fopen($HTTP_REFERER, "r"), 100000);

    if ($fd)
    {
    $start= strpos($fd, "<!-- CONTENT -->");
    $finish= strpos($fd, "<!-- /CONTENT -->");
    $length= $finish-$start;
    $code=Substr($fd, $start, $length);
    }


    echo '<html>
    <head>
    <title><?=.$Title.?></title>
    <meta name="robots" content="noindex,nofollow" />
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" language="JavaScript" src="scripts/rollover.js"></script>
    </head>
    <body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    '.$code.'

    <table width="800" align="left" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td><a href="index.htm"><img src="images/logo.gif" alt="" width="313" height="80" border="0"></a>
    <br>
    <br>
    </td>
    </tr>
    <tr>
    <td width="100%" class="txt">
    <div align="left">'.$HTTP_REFERER.'<br>
    <br>
    </div></td>
    </tr>
    <tr>
    <td align="left" width="100%" class="txt">
    <%=strbody%>
    </td>
    </tr>
    <tr>
    <td align="left" width="100%"><a href='.$HTTP_REFERER.' class="a_link">Back to Article</a>
    </td>
    </tr>
    </table>
    </body>
    </html>';
    ?>
     
    lasvegascom, Jan 24, 2006 IP
  2. Salsa

    Salsa Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't think you want the concatinating dots in there on either side of $Title. Try just this:

    <title><?php echo $Title; ?></title>
    Here you don't have $code in <?php ?>. Try this instead:

    <body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0"><?php echo $code; ?><table width="800"...

    ...again, no <?php ?>:
    Try:

    <td align="left" width="100%"><a href="<?php echo $HTTP_REFERER; ?>" class="a_link">Back to Article</a>

    Not tested, but hope that helps,
    Salsa
    ______
     
    Salsa, Jan 24, 2006 IP
  3. lasvegascom

    lasvegascom Peon

    Messages:
    438
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It still does not work. This is what i have right now.

    <?php

    $fd= fread(fopen($HTTP_REFERER, "r"), 100000);

    if ($fd)
    {
    $start= strpos($fd, "<!-- CONTENT -->");
    $finish= strpos($fd, "<!-- /CONTENT -->");
    $length= $finish-$start;
    $code=Substr($fd, $start, $length);
    }
    echo "<html>
    <head>
    <title><?php echo "$Title"; ?></title>
    <meta name="robots" content="noindex,nofollow" />
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" language="JavaScript" src="scripts/rollover.js"></script>
    </head>
    <body>

    <table width="800" align="left" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td><a href="index.htm"><img src="images/logo.gif" alt="" width="313" height="80" border="0"></a>
    <br>
    <br>
    </td>
    </tr>
    <tr>
    <td width="100%" class="txt">
    <div align="left">".$HTTP_REFERER."<br>
    <br>
    </div></td>
    </tr>
    <tr>
    <td align="left" width="100%" class="txt">
    <?php {echo "$code"; ?>
    </td>
    </tr>
    <tr>
    <td align="left" width="100%"><td align="left" width="100%"><a href="<?php echo "$HTTP_REFERER"; ?>" class="a_link">Back to Article</a>
    </td>
    </tr>
    </table>
    </body>
    </html>";
    }
    ?>
     
    lasvegascom, Jan 24, 2006 IP
  4. Salsa

    Salsa Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, what is it doing? There are a lot more ways for something to not work than there are for it to work.

    One thing, get rid of the { in "<?php {echo "$code"; ?>" line. You really have to watch stuff like that. Typos aren't tolerated. :)

    Then, if it still doesn't work, do some error checking, like, instead of

    $fd= fread(fopen($HTTP_REFERER, "r"), 100000);

    maybe change the line to:
    if (!$fd= fread(fopen($HTTP_REFERER, "r"), 100000)) die("couldn't read file");

    ...that way, if that's the problem, PHP will throw you an error message and tell you that that's a problem.

    It's also a good idea to throw some temporary echos into your script so you can hone in on the problem. Like, right after:

    $code=Substr($fd, $start, $length);

    ...try temporarily adding something like:

    echo "\$code == $code<br>\n";

    That way, if there is nothing in $code, you'll know that the problem is before that in the code, or vice versa...

    Before that, try adding:

    echo "\$HTTP_REFERER == $HTTP_REFERER<br>\n";

    ...when you see the address that you want there, you'll know that you're okay up to that point, etc.

    I hope this helps
    Salsa
    _______
     
    Salsa, Jan 24, 2006 IP
  5. lasvegascom

    lasvegascom Peon

    Messages:
    438
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I added the changes you suggested and got this error message:

    Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in /home/lvcllc/public_html/print.php on line 16

    Here is the full current code i am using:
    <?php

    if (!$fd= fread(fopen($HTTP_REFERER, "r"), 100000)) die("couldn't read file");

    if ($fd)
    {
    $start= strpos($fd, "<!-- CONTENT -->");
    $finish= strpos($fd, "<!-- /CONTENT -->");
    $length= $finish-$start;
    $code=Substr($fd, $start, $length);

    echo "\$code == $code<br>\n";
    }
    echo "<html>
    <head>
    <title><?php echo "$Title"; ?></title>
    <meta name="robots" content="noindex,nofollow" />
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" language="JavaScript" src="scripts/rollover.js"></script>
    </head>
    <body>

    <table width="800" align="left" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td><a href="index.htm"><img src="images/logo.gif" alt="" width="313" height="80" border="0"></a>
    <br>
    <br>
    </td>
    </tr>
    <tr>
    <td width="100%" class="txt">
    <div align="left">".$HTTP_REFERER."<br>
    <br>
    </div></td>
    </tr>
    <tr>
    <td align="left" width="100%" class="txt">
    <?php echo "$code"; ?>
    </td>
    </tr>
    <tr>
    <td align="left" width="100%"><td align="left" width="100%"><a href="<?php echo "$HTTP_REFERER"; ?>" class="a_link">Back to Article</a>
    </td>
    </tr>
    </table>
    </body>
    </html>";
    }
    ?>
     
    lasvegascom, Jan 24, 2006 IP
  6. Salsa

    Salsa Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    My mistake. I should have caught that before. I thought you had clsoed ?> before you started printing out the <html>... and I had you open <?php... again.

    Line 16 is:

    <title><?php echo "$Title"; ?></title>

    ...see how <?php is now opened twice?

    Rather than changing that, however, It'll be easer to go back up to line 14, where it says"

    echo "<html>

    ...delete that line and replace it with:

    ?>
    <html>

    Then also delete the two lines:

    }
    ?>

    ... at the very end of the script, and see how that works.

    Salsa
    _________
     
    Salsa, Jan 24, 2006 IP