Problem with PHP code.
Posted: Thu Sep 11, 2008 2:37 pm
Hi people,
I am having an issue with the following code (this is a cut down demonstration of the issue I am having) You can see it working here http://www.richardscarrott.co.uk/project/test.php...or more accurately not working.
It displays a blank screen with no error messages or anything, can anybody see what I am doing wrong?
I believe the out put using the $URL = 'secure.streamlinenet.co.uk/cp/index.php' should be:
I am having an issue with the following code (this is a cut down demonstration of the issue I am having) You can see it working here http://www.richardscarrott.co.uk/project/test.php...or more accurately not working.
It displays a blank screen with no error messages or anything, can anybody see what I am doing wrong?
Code: Select all
<?php
// include custom function list
require_once ('includes/functions.php');
// Create URL (will eventually be taken from form input)
$URL = 'secure.streamlinenet.co.uk/cp/index.php'; // test
//Add http:// if URL does not already contain http:// or https://
if (!string_starts_with($URL, "http://") && !string_starts_with($URL, "https://")) {
// add http:// as default (more likely)
$URL = 'http://' . $URL;
}
// Get HTML source from URL file
$URL_source = file_get_contents($URL);
// Check whether file_get_contents was succesfull, if not try using the "https://" protocol
if ($URL_source == false) {
// echo statement here to indicate first file_get_contents was unsuccessful
echo'<p>the first file_get_contents() was unsuccessful using: ' . $URL . '</p>';
// check $URL starts with http:// otehrwise URL may be misspelt (it is not a protocol issue)
if (string_starts_with($URL, "http://")) {
// replace http:// with https://
$URL = str_replace ("http://", "https://", $URL);
// get HTML source from modified URL file
$URL_source = file_get_contents($URL);
}
else {
echo '<p>Unable to read your webpage, please check the spelling is correct.</p>';
echo $URL;
// exit script;
exit;
}
}
// Check file_get_contents was succesfull, if not try using the "https://" protocol
if ($URL_source !== false) {
echo '<p>Either the first or the second file_get_contents operation was successful using: ' . $URL . '</p>';
}
?>I believe the out put using the $URL = 'secure.streamlinenet.co.uk/cp/index.php' should be:
Any insight would be much appreciated.the first file_get_contents() was unsuccessful using: http://secure.streamlinenet.co.uk/cp/index.php
Either the first or the second file_get_contents operation was successful using: https://secure.streamlinenet.co.uk/cp/index.php