"Else" Get Triggered Wrongfully!

No. I do not agree with going back to REQUEST_METHOD. I agreed with the isset check.

Once inside the IF statement, that is using an isset check, you can use filter_value to get the data passed in via the URL instead of mis-using mysql_real_escape_string

Cpradio,

Oops! I made a mistake on my previous post. Post: 20.
It was supposed to read like this:


"So, I should stick to my old code, like another is suggesting:

if(isset($_GET[“url_to_proxify”]) === TRUE)

He says I should change my new code, which was the following and my Undefined Index error would be gone:

if ($SERVER[‘REQUESTMETHOD’] == “GET”)

Seems like you are agreeing with him. But correct me if I am wrong.


Anyway, I have reverted back to the following like he and you have suggested and I believe my problems would be over as the problems really started when I switched to:

if ($SERVER[‘REQUESTMETHOD’] == “GET”)

From:

if(isset($_GET[“url_to_proxify”]) === TRUE)

No need to reply.

Thanks!

Just to clarify, you should be using:

if (isset($_GET["url_to_proxify"]) === TRUE) {
    $url_to_proxify = filter_input(INPUT_GET, 'url_to_proxify', FILTER_VALIDATE_URL);

That will prevent your undefined index warnings.

filter_input() does not cause undefined index warnings in the first place!

1 Like

True, so in theory you could do this:

$url_to_proxify = filter_input(INPUT_GET, 'url_to_proxify', FILTER_VALIDATE_URL);
if ($url_to_proxify) {

In that way, you won’t try and process $url_to_proxify if it is invalid.

1 Like

which is what I already said in post #9

(ok, it returns null if it’s not in the URL)

1 Like

I just did a google search for:
filter_input

Now oldbie folks (non newbies on php), looking at this following link, can you honestly agree it is newbie friendly tutorial:

http://php.net/manual/en/function.filter-input.php

The first thing I come across is “mixed filter input”. Why couldn’t it show examples of a “plain/simple filter input” ? Confusing!
Anyway, moved-onto the next link or so:

Now, that link is better. Even though people advise against learning from w3schools.com.
They even have an experiment tool and as you know, the more you experiment or play around, the more you learn & remember things:
https://www.w3schools.com/php/showphp.asp?filename=demo_func_filter_input.

Now you guys know, why I run a mile away from the php.net manual. It is complicated.
Good I am sticking to tutorialspoint.com. tutorialrepublic.com and codeacademy.com I am getting into. Better than the manual for beginners.

Reading these now:
https://stackoverflow.com/questions/15102796/when-to-use-filter-input
https://stackoverflow.com/questions/19945673/how-do-i-keep-google-analytics-from-corrupting-query-strings-that-contain-26
https://lukeplant.me.uk/blog/posts/why-escape-on-input-is-a-bad-idea/

A manual entry is not a tutorial …

5 Likes

You mean a reference guide is not a tutorial.
I agree. That is why I had to argue with some programmers in some forums that I won’t learn from the php.net manual (like they suggest) and would try finding other tutorial sites tailored for complete newbies. many programmers suggested I do this also and not try using the manual site as a tutorial but use it as a reference only. I am doing this from time to time. Using it as a reference to check things out. And, only using it when others show me a link to it when replying to my threads. Else, I avoid it like the plague and don’t check up on it. It puts me off from php. Their code samples are complicated.

No need to reply.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.