Folks,
I keep getting this error no matter how differently I code:
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\id\proxified_page_2.php on line 58
Here is my code:
<?php
$conn = mysqli_connect("localhost", "root", "", "e-id");
if (!$conn) {
// message to use in development to see errors
die("Database error : " . mysqli_error($conn));
// user friendly message
// die("Database error.");
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "GET">
Url: <input type = "text" name = "url_to_proxify" />
<input type = "submit" />
</form>
</body>
</html>
<?php
$url_to_proxify = "";
if(isset($_GET["url_to_proxify"]) === TRUE)
{
$url_to_proxify = trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
//WHY IS NOT THE FOLLOWING BEING ECHOED ?
echo $url_to_proxify;
$url = $url_to_proxify;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
$domain = parse_url($url, PHP_URL_HOST);
echo $domain;
//Below change 'localhost' to "./".
//eg: $pattern = array("./", "https://www.", "http://www.", "https://", "http://", "www.");
$pattern = array("localhost", "https://www.", "http://www.", "https://", "http://", "www.");
$replace = array("proxified_page_2.php?url_to_proxify=", "proxified_page_2.php?url_to_proxify=", "proxified_page_2.php?url_to_proxify=", "proxified_page_2.php?url_to_proxify=", "proxified_page_2.php?url_to_proxify=", "proxified_page_2.php?url_to_proxify=");
$phrase = str_replace($pattern, $replace, $result);
//Below code from Basic Php Proxy Video and fix from: https://stackoverflow.com/questions/22255241/preg-replace-no-ending-matching-delimiter-gt/22255455#22255455
foreach($url as $phrase)
{
//eg: $pattern = array("localhost", "./", "https://", "http://");
$phrase = preg_replace('/src="/', 'src="'.$url_to_proxify, $phrase);
$phrase = preg_replace('/action="/', 'action="proxy.php?url_to_proxify=' .$domain.$url_to_proxify, $phrase);
echo $phrase;
curl_close($ch);
}
}
?>
And no. It is not the same code you see in my other thread: else-triggered-wrongfully.
That one and this script’s aim is the same. To proxify pages without showing errors when making keyword searches on a search box.
But that one is coded with file function while this one with cURL.
How would you fix line 15 ?
foreach($page as $phrase)
{
//eg: $pattern = array("localhost", "./", "https://", "http://");
$phrase = preg_replace('/src="/', 'src="'.$url_to_proxify, $phrase);
$phrase = preg_replace('/action="/', 'action="proxy.php?url_to_proxify=' .$url_to_proxify, $phrase);
echo $phrase;
}
Been trying to fix these 2-3 scripts this whole night. Other issues solved thanks to you guys and so just one more issue left. This issue.
Thanks