Guys,
How to concatenate a $domain into a $url ?
I am trying like this:
<?php
$conn = mysqli_connect("localhost", "root", "", "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);
}
}
?>
Note the following in line 64:
$phrase = preg_replace('/action="/', 'action="proxy.php?url_to_proxify=' ".$domain"".$url_to_proxify", $phrase);
Not working. Get this error:
Parse error: syntax error, unexpected ‘"’, expecting ‘,’ or ‘)’ in C:\xampp\htdocs\id\proxified_page_2.php on line 64
Tried even like this but no luck:
$phrase = preg_replace('/action="/', 'action="proxy.php?url_to_proxify=' .$domain.$url_to_proxify, $phrase);
The above is correct ? Right ?
I have read on concatenation in the php tutorials.
Just incase you’re wondering: The script is on a file called: proxified_page_2.php.