andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


script usage problems

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> WWW Checkup
View previous topic :: View next topic  
Author Message
already_dead
Newbie


Joined: 21 Dec 2005
Posts: 11

PostPosted: Wed Dec 21, 2005 12:08 pm    Post subject: script usage problems Reply with quote

First: Excellent scripts. EXCELLENTO!
Second: wwwcheckup - I'm not getting any errors when it runs, but theres no input/output, just four links that don't do what I think they should when mousedowned:

echo "<p><a href=\"$PHP_SELF?add=1\">Add some demo sites</a></p>\n";
echo "<p><a href=\"$PHP_SELF?list=1\">List all websites (no updating)</a></p>\n";
echo "<p><a href=\"$PHP_SELF?checkup=1\">Check for updates (and make changes in database)</a></p>\n";
echo "<p><a href=\"$PHP_SELF?noupdate=1\">Check for changes (and make no changes in database)</a></p>\n";

They just change the url in the addressbar. So I went ahead and added a form that adds a website:

echo '<form action="" method="post">Add website (include http://)<br />';
echo '<input type="text" size="60" maxlength="255" name="site"> <input type="submit" value="add site"></form>';
$cu->DisplayAll();

Notice the subtile change from "<br>" to "<br />" to make it XML comply. When I fill in the form and hit submit, nothing happens except a refresh.

I added a site to the database manually, but mousedown a href=\"$PHP_SELF?list=1\ doesnt show it. Putting $cu->DisplayAll(); in the page shows the website. What am I doing wrong?

Third: Excellent script, will be purchasing if I can get it to function.
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Dec 21, 2005 6:07 pm    Post subject: Reply with quote

Hi, and welcome to the board!

Off the top of my head I'd say the problem was the $PHP_SELF variable. When I wrote the class and the demo file, register_globals was usually turned on and $PHP_SELF was used more than $_SERVER['PHP_SELF']. But with newer(ish) versions, the super globals are used and register_globals is usually (and rightly) disabled. So try having something like:

PHP:
<?php echo '<p><a href="'$_SERVER['PHP_SELF'], '?add=1">Add some demo sites</a></p>'"\n"?>


instead and see if that works out for you.

Also you are quite correct (in the other post, too) about having XHTML style tags. Again, this class (and the majority of the others) were written some time ago and I've not tweaked them and kept them as up-to-date as I should. I will endeavour to do so in the future!

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Dec 21, 2005 6:10 pm    Post subject: Reply with quote

You might also want to check out the non-mysql version I posted up, if you haven't already.

http://php.amnuts.com/forums/viewtopic.php?t=242

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
already_dead
Newbie


Joined: 21 Dec 2005
Posts: 11

PostPosted: Thu Dec 22, 2005 6:44 am    Post subject: Reply with quote

I havent modified the class, heres my page:
Code:
<?php

//
// test.wwwcheckup.php
//
// This is a document to demonstrate possible usages for the
// class.wwwcheckup.php class.
//
// Andrew Collington, 2002
// http://www.amnuts.com/ - andy@amnuts.com
//

include "class.wwwcheckup.php";

$cu = new WebsiteCheckup("user","pass","websites","database");

if (isset($_POST['site']))
{
        echo 'Adding ', $_POST['site'], ' - ', ($cu->AddWebsite($_POST['site']) ? 'succesful' : 'error, line 18'), "<br />\n";
}

if (isset($checkup))
{
    $cu->SetAutoUpdate(1);
    $cu->DisplayUpdates();
    echo "<br><br>\n\n";
}

if (isset($list))
{
    $cu->DisplayAll();
    echo "<br /><br />\n\n";
}

if (isset($noupdate))
{
    $cu->SetAutoUpdate(0);
    $cu->DisplayUpdates();
    echo "<br /><br />\n\n";
}

echo "<hr noshade>\n";
echo '<form
   action=""
   method="post">Add website(include http://)<br />';
echo '<input
   type="text"
   size="60"
   maxlength="255"
   name="site">
   <input
   type="submit"
   value="add site">
   </form>';
$cu->DisplayAll();
   // Shows the website I added to the database by hand, so we know it works

echo '<p><a href="', $_SERVER['PHP_SELF'], '?list=1">List all</a></p>', "\n";
   // Nothing
echo '<p><a href="', $_SERVER['PHP_SELF'], '?checkup=1">Check for updates (and make changes in database)</a></p>', "\n";
   // Nothing
echo '<p><a href="', $_SERVER['PHP_SELF'], '?noupdate=1">Check for changes (and make no changes in database)</a></p>', "\n";
   // Nothing
        // FYI, add=1 didn't add the demo sites either.
?>


When you fill in the form and submit, you see
Adding http://www.somesite.com/watch.html - error, line 18
then the form
then the table with the one I added by hand (shows correctly)
then the links.

What do you thinks going on with this one? I saw that you had a non-mysql version but I would really dig having it this way because eventually I would like to tie it into the main mysql database anyway. PS, where did you learn PHP? What school?
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Dec 22, 2005 7:57 am    Post subject: Reply with quote

The reason the AddWebsite method returns a false value is because no content was able to be gotten from the url. So I'd first check to see if the url is valid, and if the website is valid. If it is, check to see you have the file wrappers turned on so that the PHP file function can connect to a remote location. If that's turned off then you need to connect via a socket (an example of that can be found in this file, http://php.amnuts.com/index.php?do=view&id=13&file=class.cafepressbox.php, in the getProducts method) and get the information that way.

IF the url is valid and you hae the file wrappers on, then perhaps the website is rejecting your connection for some reason and you should perhaps investigate the headers returned. If you're using FireFox then you could install the excellent Tamper Data extension which shows all the headers for transmissions through the browser. Fab stuff!

http://tamperdata.mozdev.org/index.html

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
already_dead
Newbie


Joined: 21 Dec 2005
Posts: 11

PostPosted: Thu Dec 22, 2005 8:54 am    Post subject: Reply with quote

You guessed it - allow_url_fopen = off. I'm assuming thats the file wrapper variable set in the zend core.
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Dec 22, 2005 8:58 am    Post subject: Reply with quote

That's the ticket, yeah. It can only be set in the php.ini file, though, so hopefully you have access to that. If not, you might want to try ripping the socket stuff out of the Cafe Press random product class (link given in a previous post).

http://uk2.php.net/filesystem
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
already_dead
Newbie


Joined: 21 Dec 2005
Posts: 11

PostPosted: Thu Dec 22, 2005 9:29 am    Post subject: Reply with quote

I'm sorry to keep pestering you about this but, do you mean that all I have to do to use sockets instead is to replace:

PHP:
<?php $site = @file($website); ?>


with

PHP:
<?php $site fsockopen($website,80); ?>


?

Seems too simple to be correct. DAMN YOU PHPPPPP!
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Dec 22, 2005 11:21 am    Post subject: Reply with quote

You could get away with something really simple. Open up the socket with fsockopen as you thought, then get the response in a while loop with fgets.

I like to use an additional function to get info from a socket which includes the headers. I can then use that to do what I like with the results.

PHP:
<?php

/**
 * Given a url the function will try to connect to that site and gather 
 * header and content information (if content parameter is true).
 *
 * @author  Andrew Collington <php@amnuts.com>
 * @version 1.0.4
 * @return  bool
 * @param   string $url      The url of the page you want to get
 * @param   bool   $content  Whether we want to return the content
 * @param   string $agent    The name of the user-agent to be sent
 */
function connectViaSocket($url$content true$agent null)
{
    static 
$reponseCodes =
        array(
             -
=> 'Did not check',
             -
=> 'Could not open connection',
            
100 => 'Continue',
            
101 => 'Switching Protocols',
            
200 => 'OK',
            
201 => 'Created',
            
202 => 'Accepted',
            
203 => 'Non-Authoritative Information',
            
204 => 'No Content',
            
205 => 'Reset Content',
            
206 => 'Partial Content',
            
300 => 'Multiple Choices',
            
301 => 'Permanently at another address - consider updating link',
            
302 => 'Found at new location - consider updating link',
            
303 => 'See Other',
            
304 => 'Not Modified',
            
305 => 'Use Proxy',
            
307 => 'Temporary Redirect',
            
400 => 'Bad Request',
            
401 => 'Authorization Required',
            
402 => 'Payment Required',
            
403 => 'Forbidden',
            
404 => 'Not Found',
            
405 => 'Method Not Allowed',
            
406 => 'Not Acceptable',
            
407 => 'Proxy Authentication Required',
            
408 => 'Request Timeout',
            
409 => 'Conflict',
            
410 => 'Gone',
            
411 => 'Length Required',
            
412 => 'Precondition Failed',
            
413 => 'Request Entity Too Large',
            
414 => 'Request-URI Too Long',
            
415 => 'Unsupported Media Type',
            
416 => 'Requested Range Not Satisfiable',
            
417 => 'Expectation Failed',
            
500 => 'Internal Server Error',
            
501 => 'Not Implemented',
            
502 => 'Bad Gateway',
            
503 => 'Service Unavailable',
            
504 => 'Gateway Timeout',
            
505 => 'HTTP Version Not Supported'
        
);

    
$url_info parse_url($url);
    
$url_info['headers'] = array();
    
$url_info['content'] = '';
    
$sock = @fsockopen($url_info['host'], (isset($url_info['port']) ? $url_info['port'] : 80), $errnum$errstr$this->timeoutLength);
    if (
$sock) {
        if (isset(
$url_info['query'])) {
            
$dump = ($content 'GET ' 'HEAD ') . "{$url_info['path']}?{$url_info['query']} HTTP/1.0\r\n";
        } else {
            
$dump = ($content 'GET ' 'HEAD ') . {$url_info['path']} HTTP/1.0\r\n";
        }
        
$dump .= 'User-Agent: ' . ($agent === null 'PHP/'.phpversion() : $agent) . "\r\n";
        
$dump .= "Host: {$url_info['host']}\r\n";
        
$dump .= "Connection: close\r\n\r\n";
        
fputs($sock$dump);
        
$in_header true;
        while (
$str fgets($sock4096)) {
            if (
$in_header == true) {
                if (
$str == "\r\n") {
                    
$in_header false;
                } else {
                    if (
eregi('^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*'$str))
                    {
                        
$url_info['conn_code'] = trim(eregi_replace('^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*''\\1'$str));
                        
$url_info['conn_code'] = preg_replace('/[^0-9]/'''$url_info['conn_code']);
                    } else {
                        list(
$h$v) = explode(': '$str2);
                        if (!isset(
$url_info['headers'][$h])) {
                            
$url_info['headers'][$h] = trim($v);
                        } else {
                            
$url_info['headers'][$h] .= trim($v);
                        }
                    }
                }
            } else {
                if (
$content) {
                    
$url_info['content'] .= $str;
                }
            }
        }
        
fclose($sock);
        if (
$content) {
            
$url_info['content'] = trim($url_info['content']);
        }
        
$url_info['conn_text'] = $reponseCodes[$url_info['conn_code']];
    } else {
        
$url_info['conn_code'] = -2;
        
$url_info['conn_text'] = $reponseCodes[-2];
    }
    return 
$url_info;
}

?>


And it's used such as:

PHP:
<?php $info connectViaSocket('http://php.amnuts.com/');
print_r($info); ?>


Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
already_dead
Newbie


Joined: 21 Dec 2005
Posts: 11

PostPosted: Thu Dec 22, 2005 2:20 pm    Post subject: Reply with quote

Is there something that needs to be set for that to work? I just ran it as is and it doesnt output anything, it's dying without output before it reaches EOF. (I put a phpinfo() on the end and it doesnt show). I put the function and the snippet example you posted in the same file.

Andy, these scripts are slick as snot, but theres no comments or debugging options man. You're killing us newbs! (Nobody expects anybody to go back and add debuggers and comments to 3 year old scripts but hey, isn't this where we're expected to complain?)
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Dec 23, 2005 4:07 am    Post subject: Reply with quote

The socket functions are part of an extension to PHP which must be enabled at compile time by giving the --enable-sockets option to configure. If you didn't set up your installation of PHP then ask the person who did if this is enabled.

As for debugging, well... Some of the classes have mild debugging feedback, but others don't. If you want to do any decent debugging then you should use a dedicated debugger. If you use an IDE for your development then it may already come with a debugger (such as Zend IDE, NuSphere PHPEd, PHPEdit, and others). Just do a search on Google and check out the top few links:

http://www.google.com/search?q=php+debugger

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> WWW Checkup All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group