[Solved]403 error when submitting “http://www” via GET even after urlencode

phpThis weekend I’ve been working with a script which required me to send data via GET to another webpage coded in PHP to process it and then convert it into pdf format using dompdf. However, it was quite frustrating how it wasn’t doing what I expected it to and everytime the variable was passed it resulted in a 403 error.

First I considered it to be something to do with the size of the variable so I tested it in various ways and by cutting it down into pieces and found out that the error was due to the presence of “http://” in the variable, and then came the task to fix this issue now.

Tried various tips and tricks to solve the issue, including urlencode, htmlspecialchars and stripslashes, none worked! :/

Coming back to the point, so how to solve the issue with your server 403 error when submitting a webpage url as a variable for GET to another php page. Well the trick is to simply don’t submit the data variable containing the “http://www”.

Something it might be as simple as editing the variable entry and removing the http:// from it. However, that wasn’t possible in my case as it took data from the database of hundreds of records and it wasn’t a good idea to manipulate the whole database for this “small” , sort of, error.

The technique is to use the str_replace function to replace “http://” from the data and send it to the next php page via GET variable and then once it arrives on the next page, replace the “Replaced” word with “http://” again.

Use this as an example and modify according to your need:

$newdata = str_replace(“httpreplacedbythis”, “http://”, “$originaldata”);

Once the data is received by the next page, use the same str_replace function to replace the data back to its normal state:

$originaldata = str_replace(“http://”, “httpreplacedbythis”, “$newdata”);

str_replace replaces all the instances of the pharase to be replaced in the variable so you need to run it once only to fix the whole script!

Hope it helps! how would you solve this issue ? and let me know if you want my services to solve it for you too!

hire best wordpress php css developer
Need Help? Hire me now!
I can help you in anything related to webdevelopment, including: HTML, CSS, PHP & MySql, WordPress (plugins & themes development, others), regular expressions, server management, etc.

Leave a Reply

Your email address will not be published.