JohnnyDoomo Posted June 27, 2016 Share Posted June 27, 2016 (edited) I have a page that has an input field that requests a full url. This includes everything from the http:// to multiple directories into the site. So something similar to http://blah.com/blah/blah/test.jpg I am trying to pass this url to next page's url. So when you submit this form, the following page is http://mysite.com/?http://blah.com/blah/blah/test.jpg?blah1=1?blah2=2?blah3=3 The problem is, the url always appears like this in the following page: http://mysite.com?http%3A%2F%blah.com%2Fblah%2Fblah%2Ftest.jpg?blah1=1 I need this changed so that it shows properly. I'm new to php, and need this done in php, not javascript. I need the output or proceeding url to look like http://mysite.com/?http://blah.com/blah/blah/test.jpg I've looked into rawurl/de/encode the get variable and nothing works, as far as getting it to be what is shown in the browser url bar. This is causing me a huge headache, and no matter what I search for in Google, I can't find anything that will allow me to alter a get request BEFORE it's set to the following page, after the submit button has been clicked, but not just change the variable that the get request got, but for what it actually shows in the url field, when calling that get request. Am I going about this wrong? Am I asking for something that can/shouldn't be done? I searched high and low on stackoverflow and still nothing helps with this exact problem I'm having. I've tried stripping the http:// out of the get variable and then inserting that variable without the http:// behind my hard typed site like: http://mysite.com?http://$url but I can only echo that, I can't make that be what is actually in the url bar. Any help on this would be appreciated. If you can make your instructions very basic, that would be extremely helpful, as I am just barely learning get requests and how to pass them onto other pages. Edited June 27, 2016 by JohnnyDoomo Quote Link to comment https://forums.phpfreaks.com/topic/301404-trying-to-submit-full-url-through-input-field-into-proceeding-url/ Share on other sites More sharing options...
QuickOldCar Posted June 27, 2016 Share Posted June 27, 2016 Try this function. $url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])) { $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?" . $query_string; } If you are manually building the parameters use http_build_query() Is a few ways can go about changing the GET parameters value, either replace if exists, unset if exists and then define it as a variable and use the http_build_query. Quote Link to comment https://forums.phpfreaks.com/topic/301404-trying-to-submit-full-url-through-input-field-into-proceeding-url/#findComment-1534059 Share on other sites More sharing options...
QuickOldCar Posted June 27, 2016 Share Posted June 27, 2016 (edited) I get what you are trying to accomplish, maybe should be looking into a more dynamic pagination system. Another member made one and shared it. http://forums.phpfreaks.com/topic/291074-php-mysli-pagination-with-items-per-page-select-option/?hl=%2Bhttp_build_query&do=findComment&comment=1491152 Edited June 27, 2016 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/301404-trying-to-submit-full-url-through-input-field-into-proceeding-url/#findComment-1534060 Share on other sites More sharing options...
Jacques1 Posted June 28, 2016 Share Posted June 28, 2016 You keep saying that you need to circumvent the URL encoding. Why? To make the URL look pretty? The URL encoding is performed automatically by the browser, and it happens for a good reason: unambiguity and robustness. For example, how is the server supposed to interpret the following URL?: http://foo?x=http://bar?y=1&z=2 Does the z parameter belong to the foo or the bar URL? A human would probably say it's part of the bar URL, but it's actually a second parameter of foo. There's no such confusion with properly encoded parameters. Of course you can do pretty much anything with URLs if you're able and willing to mess with the low-level details. But I definitely don't recommend that to a beginner. Just let the browser do its job. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301404-trying-to-submit-full-url-through-input-field-into-proceeding-url/#findComment-1534065 Share on other sites More sharing options...
QuickOldCar Posted June 28, 2016 Share Posted June 28, 2016 (edited) Jacques is correct, just need to add the GET parameter to that url. x= in his example Personally I rawurlencode() them if urls I'm adding as a value of a parameter, then rawurldecode() them back for my code when displaying. If showed some code and we had an idea what are actually doing may be better methods. Such as storing the urls in a database and using an id parameter with a number in the url. Edited June 28, 2016 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/301404-trying-to-submit-full-url-through-input-field-into-proceeding-url/#findComment-1534066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.