PHP Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alex79
    Confirmed User
    • Jun 2002
    • 996

    #1

    PHP Question

    i want open an web addresse using the php function $x=file($url) ..
    here is the problem: if the $url address don't exist then i get an Warning error: "php_network_getaddresses: getaddrinfo failed"
    in a such case i don't want the warning error to be displayed.. i just want to display a message like "can't access url"

    i've tryed next code:
    $x=file($siteurl) or die("Can't access $url");
    but first i get the warning error and after that my message...

    anybody have an ideea how can i make to display just my message in the case that the $url don't exist?
  • JDog
    Confirmed User
    • Feb 2003
    • 7453

    #2
    if(!$x = fopen($url)) {
    echo "Can not access $url";
    exit;
    }

    Try that!

    jDOG
    NSCash now powering ReelProfits.com
    ALSO FEATURING: NSCash.com :: SoloDollars.com :: ReelProfits.com :: BiminiBucks.com :: VOD
    PROGRAMS COMING SOON: Greedy Bucks :: Vengeance Cash
    NOW OFFERING OVER 60 SITES
    CONTACT :: JAMES SMITH :: CHIEF TECHNOLOGY OFFICER :: ICQ (711385133)

    Comment

    • alex79
      Confirmed User
      • Jun 2002
      • 996

      #3
      Originally posted by JDog
      if(!$x = fopen($url)) {
      echo "Can not access $url";
      exit;
      }

      with this i get next:

      Warning: Wrong parameter count for fopen() in /home/****** on line 23
      Can not access http://www.********

      Comment

      • swedguy
        Confirmed User
        • Jan 2002
        • 7981

        #4
        Originally posted by alex79


        with this i get next:

        Warning: Wrong parameter count for fopen() in /home/****** on line 23
        Can not access http://www.********
        resource fopen ( string filename, string mode [, int use_include_path [, resource zcontext]])

        fopen($url, "r") would be the correct syntax.

        Comment

        • JDog
          Confirmed User
          • Feb 2003
          • 7453

          #5
          Originally posted by swedguy


          resource fopen ( string filename, string mode [, int use_include_path [, resource zcontext]])

          fopen($url, "r") would be the correct syntax.
          This is correct, I forgot the permission argument!

          jDOG
          NSCash now powering ReelProfits.com
          ALSO FEATURING: NSCash.com :: SoloDollars.com :: ReelProfits.com :: BiminiBucks.com :: VOD
          PROGRAMS COMING SOON: Greedy Bucks :: Vengeance Cash
          NOW OFFERING OVER 60 SITES
          CONTACT :: JAMES SMITH :: CHIEF TECHNOLOGY OFFICER :: ICQ (711385133)

          Comment

          • Ash@phpFX
            Confirmed User
            • Nov 2003
            • 4292

            #6
            $fd=fopen("http://www.url.com","r");
            while ($line=fgets($fd,1000))
            {
            $alltext.=$line;
            }
            fclose ($fd);

            reads it into $alltext

            Comment

            • alex79
              Confirmed User
              • Jun 2002
              • 996

              #7

              fopen($url, "r") would be the correct syntax.
              still get the same warning error like first time:

              Warning: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/*********
              Warning: fopen("http://www.aaaa.aa", "r") - Bad file descriptor in /home/*************
              Can not access http://www.aaaa.aa

              how can i escape of this warning errors?

              Comment

              • swedguy
                Confirmed User
                • Jan 2002
                • 7981

                #8
                If you only wanna suppress the PHP error messages (which is good on a live website). Add this to the top of your page:

                ini_set("display_errors", 0);

                Comment

                • alex79
                  Confirmed User
                  • Jun 2002
                  • 996

                  #9
                  Originally posted by asher
                  $fd=fopen("http://www.url.com","r");
                  while ($line=fgets($fd,1000))
                  {
                  $alltext.=$line;
                  }
                  fclose ($fd);

                  reads it into $alltext
                  thanks but i get same errors with this code.. the problem is not that i can't read the file.. if the $url is correct and exist then i can read him withot problems with file() or fopen().... the problem is that when the $url don't exist then u get these warning errors displayed.. in a such case i just want to be displayed my eror text without warnings

                  Comment

                  • swedguy
                    Confirmed User
                    • Jan 2002
                    • 7981

                    #10
                    ...or add an @ in front of the fopen()

                    Comment

                    • Ash@phpFX
                      Confirmed User
                      • Nov 2003
                      • 4292

                      #11
                      preceed the function with an @
                      that will stop the warnings
                      like @fopen()

                      Comment

                      • swedguy
                        Confirmed User
                        • Jan 2002
                        • 7981

                        #12
                        What it will look like:

                        $x = @file($siteurl);

                        if ($x) {
                        .....
                        } else {
                        print "Could not connect to $url";
                        exit;
                        }

                        Comment

                        • alex79
                          Confirmed User
                          • Jun 2002
                          • 996

                          #13
                          ok.. @file() works fine.. thanks to everybody

                          Comment

                          Working...