php-windows Digest 29 Apr 2004 03:29:51 -0000 Issue 2230

Topics (messages 23570 through 23582):

HTTP Header Viewer... Do I need regexps?
        23570 by: Leif Gregory
        23577 by: Jason Barnett

Automated Login
        23571 by: Ron.Herhuth.tatumpartners.com
        23572 by: Jason Barnett
        23573 by: Ken Sanderson
        23575 by: Svensson, B.A.T. (HKG)
        23582 by: Manuel Lemos

problem with web pages and php
        23574 by: Mike Ryan
        23576 by: Jason Barnett

Re: most latest file
        23578 by: Harpreet

Re: [PHP] HTTP Header Viewer... Do I need regexps?
        23579 by: Tom Rogers
        23581 by: Tom Rogers

Run batch files using php
        23580 by: Harpreet

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Hello everyone,

  I've been putzing with this for about a week on and off now.

  I've googled like crazy and tried to figure out the regexps, but I
  can't just get it.

  What I'm doing is taking some code I found to show me the HTTP
  headers from a remote server and making it a bit more dynamic with a
  runtime input, and to format the output nicely. I can retrieve the
  headers just fine, but I can't get the output broken out into pieces
  from the returned single line.

  i.e.
  
  HTTP/1.1 200 OK Date: Tue, 20 Apr 2004 17:28:23 GMT Server: Microsoft-IIS/5.0 
Last-modified: Thu, 01 Jan 2004 19:56:39 GMT Connection: close Content-type: text/html

  I want to format it as such by breaking each line into its own
  array element:

  HTTP/1.1 200 OK
  Date: Tue, 20 Apr 2004 17:28:23 GMT
  Server: Microsoft-IIS/5.0
  Last-modified: Thu, 01 Jan 2004 19:56:39 GMT
  Connection: close
  Content-type: text/html

  Any help would really be appreciated.

  BTW, this is PHP 4.3.4 on Win2K Pro running under Sambar.

  Here's the code:

,------ [  ]
| <HTML>
| <HEAD>
| </HEAD>
| <BODY>
| 
| This will return the HTTP headers for a site to determine SERVER type, cookies, 
sessions etc.
| <br><br>
| 
| <form>
| <input type="text" name="URL" value="URL">
| <input type="SUBMIT" name="SUBMIT">
| </form>
| 
| <? 
| if (isset($_GET['URL']))
| {
|   $fp = fsockopen ($_GET['URL'], 80, $errno, $errstr, 30); 
|   if (!$fp) 
|     { 
|       echo "$errstr ($errno)<br>\n"; 
|       } 
|   else 
|     { 
|       fputs($fp, "GET / HTTP/1.0\r\nHost: " . $_GET['URL'] . "\r\n\r\n"); 
|       
|     //This part allows me to see the headers but on a single line
|       //while (!feof($fp))
|       //{ 
|       //  echo fgets($fp,256); 
|       //  } 
|       //fclose ($fp); 
|       //} 
|       
|     //This is the part I can't figure out
|       preg_match_all ("Date:\s*.*?\s\S*:\s*|\z", fgets($fp,256), $server);
|       echo $server;
|       fclose($fp);
|       }
|
|
|     //Some other stuff I tried.
|       //preg_match_all ("/HTTP.*?K/", fgets($fp,256), $server);
|       //echo $server[1];
|       //fclose($fp);
|       //}
|       //echo "Method: " . substr("$pagedata", 0, 15) . "<br />";
|       //echo substr("$pagedata", 16, 36) . "<br />";
|       //echo substr("$pagedata", 52, 67) . "<br />";
|
|   }
|   
| ?>
| </BODY>
| </HTML>
`----------

  


Tagline of the day:
The problem with paradigms is that shift happens.



-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 2.10 RC/1 under Windows 2000 5.0
Build 2195 Service Pack 4 on a Pentium 4 2GHz with 512MB

--- End Message ---
--- Begin Message ---
Leif Gregory wrote:

Hello everyone,

  I've been putzing with this for about a week on and off now.

  I've googled like crazy and tried to figure out the regexps, but I
  can't just get it.

  What I'm doing is taking some code I found to show me the HTTP
  headers from a remote server and making it a bit more dynamic with a
  runtime input, and to format the output nicely. I can retrieve the
  headers just fine, but I can't get the output broken out into pieces
  from the returned single line.

i.e.
HTTP/1.1 200 OK Date: Tue, 20 Apr 2004 17:28:23 GMT Server: Microsoft-IIS/5.0 Last-modified: Thu, 01 Jan 2004 19:56:39 GMT Connection: close Content-type: text/html


  I want to format it as such by breaking each line into its own
  array element:

To split a string into an array you can use preg_split() or split(). http://www.php.net/manual/en/function.preg-split.php http://www.php.net/split



HTTP/1.1 200 OK Date: Tue, 20 Apr 2004 17:28:23 GMT Server: Microsoft-IIS/5.0 Last-modified: Thu, 01 Jan 2004 19:56:39 GMT Connection: close Content-type: text/html

  Any help would really be appreciated.


This will split up your request string. The key here is that you use parentheses in order to search for any item in the group followed by a colon and a space.


<?php

$header = 'HTTP/1.1 200 OK Date: Tue, 20 Apr 2004 17:28:23 GMT Server: Microsoft-IIS/5.0 Last-modified: Thu, 01 Jan 2004 19:56:39 GMT Connection: close Content-type: text/html';

$splitHTTP = array(
  'Date',
  'Server',
  'Last-Modified',
  'Connection',
  'Content-type',
);

$values = preg_split('/('.implode('|', $splitHTTP).'):\s/', $header);

echo '<pre>';
print_r($values);
echo '</pre>';

?>
--- End Message ---
--- Begin Message ---
I am trying to build an automated dashboard sort of thing that goes and
checks if several of my clients sites are functioning and reporting back
the findings.

I have two types of URLs that I'm attmepting to check.

1) Typical static URLs example: http://www.yahoo.com

2) I would like to have the app attempt to login by sending the Login
handling page the username and password as POST data.  This seems like it
would be easy if it were a GET form but it is a POST form.

How can I hit the pages and report back if the site is working and the
page loaded, and in the case of the login pages, if I was able to have the
script successfully login?

Thanks,
Ron










--- End Message ---
--- Begin Message ---
Ron Herhuth wrote:

I am trying to build an automated dashboard sort of thing that goes and
checks if several of my clients sites are functioning and reporting back
the findings.

I have two types of URLs that I'm attmepting to check.

1) Typical static URLs example: http://www.yahoo.com

2) I would like to have the app attempt to login by sending the Login
handling page the username and password as POST data.  This seems like it
would be easy if it were a GET form but it is a POST form.

Some POST forms can actually be passed information in the query string, as if it was using the GET method. I use this bookmark to test it:


javascript:(function(){var x,i; x = document.forms; for (i = 0; i < x.length; ++i) x[i].method=%22get%22; alert(%22Changed %22 + x.length + %22 forms to use the GET method. After submitting a form from this page, you should be able to bookmark the result.%22); })();

Thanks to Jesse Ruderman's website for this very handy bookmark!


How can I hit the pages and report back if the site is working and the page loaded, and in the case of the login pages, if I was able to have the script successfully login?

Thanks,
Ron

The cURL extension is probably going to help you with this. http://www.php.net/curl

--- End Message ---
--- Begin Message ---
You can use fsockopen() to build the HTTP header you are sending to a
web site in order to mimic a post form submission.

Ken

-----Original Message-----
From: Jason Barnett [mailto:[EMAIL PROTECTED] 
Sent: April 28, 2004 3:25 PM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] Re: Automated Login


Ron Herhuth wrote:

> I am trying to build an automated dashboard sort of thing that goes 
> and checks if several of my clients sites are functioning and 
> reporting back the findings.
> 
> I have two types of URLs that I'm attmepting to check.
> 
> 1) Typical static URLs example: http://www.yahoo.com
> 
> 2) I would like to have the app attempt to login by sending the Login 
> handling page the username and password as POST data.  This seems like

> it would be easy if it were a GET form but it is a POST form.

Some POST forms can actually be passed information in the query string, 
as if it was using the GET method.  I use this bookmark to test it:

javascript:(function(){var x,i; x = document.forms; for (i = 0; i < 
x.length; ++i) x[i].method=%22get%22; alert(%22Changed %22 + x.length + 
%22 forms to use the GET method.  After submitting a form from this 
page, you should be able to bookmark the result.%22); })();

Thanks to Jesse Ruderman's website for this very handy bookmark!

> 
> How can I hit the pages and report back if the site is working and the

> page loaded, and in the case of the login pages, if I was able to have

> the script successfully login?
> 
> Thanks,
> Ron

The cURL extension is probably going to help you with this.
http://www.php.net/curl

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
Connect to port 80, and send raw HTTP data. 

-----Original Message-----
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: 2004-04-28 21:22
Subject: [PHP-WIN] Automated Login


I am trying to build an automated dashboard sort of thing that goes and
checks if several of my clients sites are functioning and reporting back
the findings.

I have two types of URLs that I'm attmepting to check.

1) Typical static URLs example: http://www.yahoo.com

2) I would like to have the app attempt to login by sending the Login
handling page the username and password as POST data.  This seems like
it
would be easy if it were a GET form but it is a POST form.

How can I hit the pages and report back if the site is working and the
page loaded, and in the case of the login pages, if I was able to have
the
script successfully login?

Thanks,
Ron

--- End Message ---
--- Begin Message ---
Hello,

On 04/28/2004 04:22 PM, Ron Herhuth wrote:
I am trying to build an automated dashboard sort of thing that goes and
checks if several of my clients sites are functioning and reporting back
the findings.

I have two types of URLs that I'm attmepting to check.

1) Typical static URLs example: http://www.yahoo.com

2) I would like to have the app attempt to login by sending the Login
handling page the username and password as POST data.  This seems like it
would be easy if it were a GET form but it is a POST form.

How can I hit the pages and report back if the site is working and the
page loaded, and in the case of the login pages, if I was able to have the
script successfully login?

You may want to try this HTTP client class that besides supporting submiting POST form requests to an HTTP server, it also can keep track of cookies that are returned and page redirection if necessary:


http://www.phpclasses.org/httpclient


--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html

--- End Message ---
--- Begin Message --- I have downloaded mysql-4.0.18-win, php-4.3.6, webcalendar and apache2 webserver

I am retrieving files from my server so I know the webserver is correct but when I try to access the day.php file all I am getting is the code to show up on the screen.

I have tried to add to the http.config file the code for both cgi and module changes and restarted the server several time what am I missing???
--- End Message ---
--- Begin Message ---
Mike Ryan wrote:

I have downloaded mysql-4.0.18-win, php-4.3.6, webcalendar and apache2 webserver

I am retrieving files from my server so I know the webserver is correct but when I try to access the day.php file all I am getting is the code to show up on the screen.

I have tried to add to the http.config file the code for both cgi and module changes and restarted the server several time what am I missing???

Thus sayeth PHP's online manual:

AddType application/x-httpd-php .php .phtml

http://www.php.net/install.apache
--- End Message ---
--- Begin Message ---
I wrote a batch file using php . Can I run this batch file using the system
or some other command.

Please help

--- End Message ---
--- Begin Message ---
Hi,

Thursday, April 29, 2004, 1:31:07 AM, you wrote:
LG> Hello everyone,

LG>   I've been putzing with this for about a week on and off now.

LG>   I've googled like crazy and tried to figure out the regexps, but I
LG>   can't just get it.

LG>   What I'm doing is taking some code I found to show me the HTTP
LG>   headers from a remote server and making it a bit more dynamic with a
LG>   runtime input, and to format the output nicely. I can retrieve the
LG>   headers just fine, but I can't get the output broken out into pieces
LG>   from the returned single line.

LG>   i.e.
  
LG>   HTTP/1.1 200 OK Date: Tue, 20 Apr 2004 17:28:23 GMT Server:
LG> Microsoft-IIS/5.0 Last-modified: Thu, 01 Jan 2004 19:56:39 GMT
LG> Connection: close Content-type: text/html

LG>   I want to format it as such by breaking each line into its own
LG>   array element:

LG>   HTTP/1.1 200 OK
LG>   Date: Tue, 20 Apr 2004 17:28:23 GMT
LG>   Server: Microsoft-IIS/5.0
LG>   Last-modified: Thu, 01 Jan 2004 19:56:39 GMT
LG>   Connection: close
LG>   Content-type: text/html

LG>   Any help would really be appreciated.

LG>   BTW, this is PHP 4.3.4 on Win2K Pro running under Sambar.

LG>   Here's the code:

LG> ,------ [  ]
LG> | <HTML>
LG> | <HEAD>
LG> | </HEAD>
LG> | <BODY>
LG> | 
LG> | This will return the HTTP headers for a site to determine
LG> SERVER type, cookies, sessions etc.
LG> | <br><br>
LG> | 
LG> | <form>
LG> | <input type="text" name="URL" value="URL">
LG> | <input type="SUBMIT" name="SUBMIT">
LG> | </form>
LG> | 
LG> | <? 
LG> | if (isset($_GET['URL']))
LG> | {
LG> |   $fp = fsockopen ($_GET['URL'], 80, $errno, $errstr, 30); 
LG> |   if (!$fp) 
LG> |     { 
LG> |       echo "$errstr ($errno)<br>\n"; 
LG> |       } 
LG> |   else 
LG> |     { 
LG> |       fputs($fp, "GET / HTTP/1.0\r\nHost: " . $_GET['URL'] . "\r\n\r\n");
LG> |       
LG> |     //This part allows me to see the headers but on a single line
LG> |       //while (!feof($fp))
LG> |       //{ 
LG> |       //  echo fgets($fp,256); 
LG> |       //  } 
LG> |       //fclose ($fp); 
LG> |       //} 
LG> |       
LG> |     //This is the part I can't figure out
LG> |       preg_match_all ("Date:\s*.*?\s\S*:\s*|\z", fgets($fp,256), $server);
LG> |       echo $server;
LG> |       fclose($fp);
LG> |       }
LG> |
LG> |
LG> |     //Some other stuff I tried.
LG> |       //preg_match_all ("/HTTP.*?K/", fgets($fp,256), $server);
LG> |       //echo $server[1];
LG> |       //fclose($fp);
LG> |       //}
LG> |       //echo "Method: " . substr("$pagedata", 0, 15) . "<br />";
LG> |       //echo substr("$pagedata", 16, 36) . "<br />";
LG> |       //echo substr("$pagedata", 52, 67) . "<br />";
LG> |
LG> |   }
LG> |   
| ?>>
LG> | </BODY>
LG> | </HTML>
LG> `----------

  


LG> Tagline of the day:
LG> The problem with paradigms is that shift happens.



LG> -- 
LG> Leif (TB lists moderator and fellow end user).

LG> Using The Bat! 2.10 RC/1 under Windows 2000 5.0
LG> Build 2195 Service Pack 4 on a Pentium 4 2GHz with 512MB


The header has line breaks you will need to nl2br() to view them in
html

-- 
regards,
Tom

--- End Message ---
--- Begin Message ---
Hi,

Thursday, April 29, 2004, 10:08:27 AM, you wrote:

TR> The header has line breaks you will need to nl2br() to view them in
TR> html

TR> -- 
TR> regards,
TR> Tom

This should split up the header for you:


$http = "HTTP/1.1 200 OK\r\nDate: Tue, 20 Apr 2004 17:28:23 GMT\r\nServer: 
Microsoft-IIS/5.0\r\nLast-modified: Thu, 01 Jan 2004 19:56:39 GMT\r\nConnection: 
close\r\nContent-type: text/html\r\n";

preg_match_all('!.*?\sOK|\s([\w\-]+):\s(.*?)$!mis',$http,$match);

echo '<pre>'.print_r($match,1).'</pre>';



-- 
regards,
Tom

--- End Message ---
--- Begin Message ---
I wrote a batch file using php . Can I run this batch file using php with
the system or some other command.

Please help

--- End Message ---

Reply via email to