Thanks man! In 5 secs, you solved my issue that I was overlooking!
But new issue …
Can anyone figure-out why I get these errors ?
Notice: Undefined index: url_to_proxify in C:\xampp\htdocs\id\proxy.php on line 7
Warning: file(): Filename cannot be empty in C:\xampp\htdocs\id\proxy.php on line 14
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\id\proxy.php on line 15
I already included a file name and so I should not get this error.
Using the script, type “http://google.com” in the text box and then click the “submit” button. You will be redirected to google.com.
Then, search google and you will see these errors mentioned above.
$conn = mysqli_connect("localhost", "root", "", "id");
if ($_SERVER['REQUEST_METHOD'] == "GET")
$url_to_proxify = trim(mysqli_real_escape_string($conn,$_GET["url_to_proxify"]));
//WHY IS NOT THE FOLLOWING BEING ECHOED ?
//WHY IS NOT THE FOLLOWING CODE GETTING TRIGGERED AFTER SUBMIT BUTTON HAS BEEN CLICKED ?
$page = file($url_to_proxify);
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 'The "else" got triggered in the "if" condition!';
<form action = "<?php $_PHP_SELF ?>" method = "GET">
Url: <input type = "text" name = "url_to_proxify" />
<input type = "submit" />
I suspect the issue is this …
When I click the Google Search box, I am taken to a SERP that has no google domain. Now, I need to deal with this by finding a proper regex that will grab the domain name from any url. I am googling for it but too many links show different ways of doing it and so if you guys know a regex then you are welcome to mention it.
You’re missing the point. The get check will ALWAYS return true, so it always goes into it. So you either need to also check for a value in url_to_proxify or replace the two instances of GET to POST. Replacing the instances to POST would probably be better in the long run
You are thinking of $_REQUEST but are missing the point like Dave said. Get is the “normal” request method for any page, so it’s going to be true in most cases (where the request method is not something else).
Yeah, I did miss the point!
I forgot that, if my url contains the “?” and the “=” which are related to the GET, then I am already triggering the GET, without giving the chance for the script to use the IF condition in the script flow. (Eg. 3rd line of the script in our example).
So, what you are saying is, if I put a link to the following on my webpage: http://localhost/id/proxy.php?url_to_proxify=http://www.ebay.com
and if any visitor clicks it or if the visitor directly types that in their browser then the 3rd line will always prove to be true:
if ($_SERVER[‘REQUEST_METHOD’] == “GET”)
Hence, the GET will always get triggered. Therefore, the following line of code will be ignored or be rendered useless:
Yeah, I read mysqli_real_escape_string is outdated.
Let’s see how you would change this line to what.
Best you update my script on your end and just paste it here so newbies all can be clear on what you are hinting. Not everyone can understand hints.