/    Sign up×
Community /Pin to ProfileBookmark

Folks,

This is weird.
Look:

““
if(!ISSET($_GET[‘user_id’]))
{
echo ‘NOT SET’;
““

I navigate to:
http://localhost/test/home.php?user_id=

And expect to get the echo but I don’t.
Since ‘user_id=’ is blank, then it means $_GET[‘user_id’] not set. Right ?
I only get the echo, if I navigate to:
http://localhost/test/home.php.

What is wrong ? How to fix it ?
Must do like this ? …

““
if(!ISSET($_GET[‘user_id’]) || empty($_GET[‘user_id’]))
{
echo ‘NOT SET’;
““

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 09.2020 — No, it means $_GET['user_id'] is set to an empty string.
Copy linkTweet thisAlerts:
@NachfolgerNov 10.2020 — > @developer_web#1624928 Since 'user_id=' is blank, then it means $_GET['user_id'] not set. Right ?

The utility of the function isset is within the name of the function itself. Ask yourself, is user_id set when you visit the URL http://localhost/test/home.php?user_id=? Yes. Yes it is. PHP doesn't care about the VALUE of the variable passed, only that the variable is defined in the scope.
Copy linkTweet thisAlerts:
@developer_webauthorNov 10.2020 — @Nachfolger#1624953

I learnt something from @NogDog and you.

(Tagging NogDog above).

Pagination tutorial shows to use is_numeric to check if value is number or not:

$limit = ISSET($_GET['limit']) && is_numeric($_GET['limit']) ? $_GET['limit'] : 10;


However, I used is_int on one place in same script to check if value is number or not:

if(ISSET($_SESSION['user_id']) && !empty($_SESSION['user_id']) && is_int($_SESSION['user_id']))

Should I switch above to is_numeric or keep as is ?
Copy linkTweet thisAlerts:
@developer_webauthorNov 10.2020 — Look, what I found:

https://nexladder.com/blog/what-is-difference-between-is_int-vs-is_integer-vs-is_numeric-in-php/

Now, Based on following, should I use: filter_var or not ? (FILTER_VALIDATE_INT).

https://stackoverflow.com/questions/8307104/is-numeric-vs-is-float-vs-is-int
Copy linkTweet thisAlerts:
@NachfolgerNov 10.2020 — > @developer_web#1624967 Pagination tutorial shows to use is_numeric to check if value is number or not:
>
> ``$limit = ISSET($_GET['limit']) &amp;&amp; is_numeric($_GET['limit']) ? $_GET['limit'] : 10;`</C>
<i>&gt; </i>
<i>&gt; </i>However, I used is_int on one place in same script to check if value is number or not:
<i>&gt; </i>
<i>&gt; </i><C>
`if(ISSET($_SESSION['user_id']) &amp;&amp; !empty($_SESSION['user_id']) &amp;&amp; is_int($_SESSION['user_id']))`</C>
<i>&gt; </i>
<i>&gt; </i>Should I switch above to is_numeric or keep as is ?</QUOTE>

I suspect it won't work. <C>
is_int</C> requires strict "typing"--Aka the int value of '1' (A string with only 1 in it) is not an integer. However, is_numeric does not care. This means that '1' or 1 would work and be considered numeric.

I haven't tested this, but unless PHP parses $_GET values types, <C>
$_GET['limit']</C> will be a string--And thus, not considered an int according to <C>is_int`
.
Copy linkTweet thisAlerts:
@developer_webauthorNov 10.2020 — @Nachfolger#1624969

Switched everything to use is_numeric.

Do your test. You will learn something new atleast thanks to my thread and question. Stay hooked to me. One way or the other, you should benefit for doing so. Not being sarcastic. Being honest.

Here invitations for you to chime in:

https://www.webdeveloper.com/d/391752-cannot-an-iframe-have-variables-as-their-url-alue/3

https://www.webdeveloper.com/d/391094-how-to-echo-serverphp-self-on-links/22

Cheers.
×

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 5.4,
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,
)...