/    Sign up×
Community /Pin to ProfileBookmark

Folks,

Look at this mystery code.
Following are 2 codes.
First one by NogDog.
Second one is an update of NogDog’s code by Zorg.
The differences between the codes are that, NogDog’s line is this:

[code]
foreach($query_parts as $q_key => $q_value) {
$query_string_parts[] = urlencode($q_key).’=’.urlencode($q_value);
}
[/code]

Zorg’s line is this:

[code]
foreach($query_parts as $q_key => $q_value) {
// assemble and check if value is numeric
$query_string_parts[] = urlencode($q_key).’=’.(is_numeric($q_value) ? intval($q_value) :urlencode($q_value));
}
[/code]

I had asked Zorg to add intval() and he did. But on Nogdog’s code.
And the difference between the two’s code is that, NogDog defines the $url and calls the prepare_url() function at the top. Before the prepare_url() function’s code.

[code]
$url = ‘http://nogdog.com/cat/subcat?var 1=value 1&var2=2&this other=thing&number is=12’;
echo prepare_url($url) . “n”;
[/code]

While Zorg defines the $url and calls the prepare_url() function at the bottom. After the prepare_url() function’s code.

[code]
$url = ‘http://zorg.com/cat/subcat?var 1=value 1&var2=2&this other=thing&number is=13’;
echo prepare_url($url);
[/code]

Apart from that, both’s code is the same.
So, if both the code is the same, then why does Nogdog’s code output like this:
**http://nogdog.com/cat/subcat?var_1=value+1&var2=2&this_other=thing&number_is=12**

And, why does Zorg’s code output like this:
**http%3A%2F%2Fzorg.com%2Fcat%2Fsubcat?var_1=value+1&var2=2&this_other=thing&number_is=13**

What is this new mystery ?

Anyway, here is the main thread where this mystery was spotted:
https://www.webdeveloper.com/d/394997-how-to-analyze-url-to-auto-add-appropriate-encoding-on-appropriate-spots/29
I’d appreciate if you folks can engage there aswell. But after responding to this post here first, orcourse.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorAug 18.2021 — @Zorg

Do you mind solving this mystery because it's done my head in.
Copy linkTweet thisAlerts:
@developer_webauthorAug 18.2021 — I am told this is causing the issue but how to fix this issue ?

$encodedHostPath = rawurlencode("{$scheme}://{$host}{$path}");
Copy linkTweet thisAlerts:
@ginerjmAug 18.2021 — What are you being told? Is it an error message that you could relate to us?
Copy linkTweet thisAlerts:
@developer_webauthorAug 18.2021 — @ginerjm#1635663

Ignore my previous post. That's a confusion on my part. **SORRY!**

Now, can you spot why the 2bd code outputs in encoded format while the 1st doesn't ? I really need to fix the 2nd code.
Copy linkTweet thisAlerts:
@developer_webauthorAug 18.2021 — Ooops!

I forgot to add the 2 codes in my original post. Unable to do so now and so need to continue this in another thread ....

https://www.webdeveloper.com/d/396080-mystery-code-continued
Copy linkTweet thisAlerts:
@NogDogAug 18.2021 — > @developer_web#1635675 so need to continue this in another thread

Closing this one then.
Copy linkTweet thisAlerts:
@developer_webauthorAug 18.2021 — @NogDog

Do you mind deleting this whole thread ?
Copy linkTweet thisAlerts:
@NogDogAug 18.2021 — {"locked":true}
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...