SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    ********* Addict
    Join Date
    Apr 2000
    Location
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello. I am having problems using the static home page trick Kevin showed us on the PHP/MySQL tutorial. Here's my code:

    Code:
    <!-- generateindex.php -->
    <?php
      // Sets the files we'll be using
      $srcurl         = "http://www.tweakpro.com/index.php";
      $tempfilename   = "/home/www/pedro_gb/tweakpro.com/docs/tempindex.html";
      $targetfilename = "/home/www/pedro_gb/tweakpro.com/docs/index.html";
    ?>
    <HTML>
    <HEAD>
    <TITLE>TweakPro.com Administration</TITLE>
    </HEAD>
    <BODY>
    <?php require("header.html");?>
    <P>Generating <?php echo("$targetfilename"); ?>...</P>
    <?php
    @unlink($tempfilename);
    $dynpage = fopen($srcurl, 'r');
    if (!$dynpage) {
    echo("<P>Unable to load $srcurl. Static page ".
    "update aborted!</P>");
    exit();
    }
    $htmldata = fread($dynpage, 1024*1024);
    fclose($dynpage);
    $tempfile = fopen($tempfilename, 'w');
    if (!$tempfile) {
    echo("<P>Unable to open temporary file ".
    "($tempfilename) for writing. Static page ".
    "update aborted!</P>");
    exit();
    }
    fwrite($tempfile, $htmldata);
    fclose($tempfile);
    $ok = copy($tempfilename, $targetfilename);
    unlink($tempfilename);
    ?>
    <P>Static page successfully updated!</P>
    </BODY>
    </HTML>
    And here's my problem:

    If I set $srcurl as the hard drive path, it works but instead of the content ending up as the dynamically generated page, it ends up as the actual code.
    If I set $srcurl as http://localhost/index.php it gives me this:

    Warning: fopen("http://localhost/index.php","r") - Connection refused in /home/www/pedro_gb/tweakpro.com/docs/admin/generateindex.php on line 17

    And, finally, if I set $srcurl as http://www.tweakpro.com it gives me this:

    Warning: fopen("http://www.tweakpro.com/index.php","r") - Undefined error: 0 in /home/www/pedro_gb/tweakpro.com/docs/admin/generateindex.php on line 17

    What could be wrong? Thanks in advance!

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    pedro,

    The URL you are trying to access is password-protected. This is why you're getting a "connection refused" error. You need to give PHP the username/password to connect to the URL. Thus,

    Code:
    $srcurl = "http://user:pass@www.tweakpro.com/index.php";
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    ********* Addict
    Join Date
    Apr 2000
    Location
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ooooooooooooooops. It was all my fault! How stupid!

    Anyway, thanks very much for pointing that out!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •