Page 1 of 1
properly escaping inside a string
Posted: Thu Apr 06, 2006 3:43 am
by malcolmboston
i have this
Code: Select all
fputs($fp, 'GET / HTTP/1.0'.PHP_EOL.'Host: http://www.devnetwork.net'.PHP_EOL.PHP_EOL);
i want to change it to this..
Code: Select all
fputs($fp, 'GET / HTTP/1.0'.PHP_EOL.'Host: $URL'.PHP_EOL.PHP_EOL);
however i get a parse error, ive tried several ways to no avail, can someone point me in the right direction pls
Posted: Thu Apr 06, 2006 4:17 am
by Maugrim_The_Reaper
Try:
Code: Select all
fputs($fp, 'GET / HTTP/1.0' . PHP_EOL . 'Host: ' . $URL . PHP_EOL . PHP_EOL);
Posted: Thu Apr 06, 2006 4:18 am
by Maugrim_The_Reaper
If that won't work, post the full parse error (excluding your server path)
Posted: Thu Apr 06, 2006 4:30 am
by malcolmboston
using this..
Code: Select all
<?php
function checkValidURL ($URL) {
$fp = @fsockopen($URL, 80, $errno, $errstr,30);
if ($fp) {
fputs($fp, 'GET / HTTP/1.0' . PHP_EOL . 'Host: ' . $URL . PHP_EOL . PHP_EOL);
do {
$sourceCode = fread($fp, 512);
#echo $sourceCode;
return TRUE;
}
while (strlen($sourceCode));
} else {
return FALSE;
}
}
function checkURLForLink () {
//
}
$isValid = checkValidURL ("http://www.evolution-interactive.co.uk");
if ($isValid === TRUE) {
echo 'Site is valid';
} else {
echo 'Site is invalid';
}
?>
say its an invalid site, but when i statically define the site (without $URL) it works fine
ps. i hate the new PHP tag, could seriously do with some CSS styling
Posted: Thu Apr 06, 2006 4:53 am
by timvw
Actually, i don't think you're really interested in the "body" of the http response... So i suggest you perform a HEAD instead of GET.. Saves a ton of bandwith...
Anyway, with HTTP1.0 you should use the absolute URL in the request string, thus GET $URL instead of GET / (Or as i suggested HEAD $URL)
The first line you recieve back is in the form of: HTTP-Version SP Status-Code SP Reason-Phrase CRLF.
Now all you have to do is analyze the status-code.
- 1xx: Informational - Request received, continuing process
- 2xx: Success - The action was successfully received,
understood, and accepted
- 3xx: Redirection - Further action must be taken in order to
complete the request
- 4xx: Client Error - The request contains bad syntax or cannot
be fulfilled
- 5xx: Server Error - The server failed to fulfill an apparently
valid request