PHP $_GET if statement not working [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
<?php
if (empty(htmlspecialchars($_GET["default"]))) {
echo 'Click to type...';
} else {
echo urldecode(htmlspecialchars($_GET["default"]));
}
?>
My code is malfunctioning. Instead of echoing "Click to type..." it does nothing. What is wrong? Thanks so much, I am a noob at PHP.

try:
if (!isset($_GET["default"]) || empty(htmlspecialchars($_GET["default"]))) {
Do you have error_reporting on?

Why the do you have htmlspecialchars inside your if? You don't need it if you think about it for a second.
The recommendation I can give you is to check your request with some debugging (var_dump on your $_GET or using xdebug).
You can also check your URL to see if you have something like localhost/someaction.php?default=something&other_get_parameter=somethingelse&..... If it's on a form you can use you can check on your developer tools in your browser.

Related

Error when trying to do a redirect using the header() method [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm using this code to redirect but it shows error
<?php
header(Location: . site_url("./admin/dashboard"));
die();
I know its a small problem. Still if anyone can help I will be grateful
You should add quotes to your string.
<?php
header('Location:' . site_url("./admin/dashboard"));
die();
Use something like this, it's a good idea to put the full address to redirect but can do this with the relative address.
Note: you must put Location: in quite.
<?php
header("Location: ". site_url("./admin/dashboard")); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>

PHP Sessions, Roles and IF statements [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a question about which one is better? any feedback?
<?php
if (htmlentities($_SESSION['user_role'], ENT_QUOTES) != 'R') {
}
?>
OR
<?php
if ($_SESSION['user_role'] != 'R') {
}
?>
The purpose of htmlentities is to change things to valid HTML. All you care about here is whether the thing in $_SESSION is 'R,' and changing it to valid HTML won't alter that (as 'R,' like any other ASCII character, is already valid HTML).
Since there's no need for htmlentities, skip it.

Get $_GET value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to make a simple PHP program. I am trying to get the value from the URL and check if the dev is equal to true. I am using this code:
if($_GET['dev']==true){...}else if($_GET['dev']==false){...}
$_GET variable are all strings, you will need to cast it to a boolean
if (isset($_GET['dev']))
{
$dev= (bool) $_GET['dev'];
if($dev){
}
}
details are not enough, tell us more about your problem.
maybe you need to compare dev to a string and not to boolean:
if($_GET['dev']=="true"){...}else if($_GET['dev']=="false"){...}

<? print $var; ?> dangerous or not? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I remember someone told me a variable had to be initialized, but I'm wondering how can printing a variable can be dangerous, nobody can include my php file from a distant server, and the variable is empty when loading the php script, no ?
Then if I have this php file:
<?
print $var; //or any other use of the variable like mysql...
?>
Is it dangerous?
It's not necessarily dangerous, but you will get a notice that $var is undefined, if error_reporting is on.

Inputting php the right way....GET php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hello I was wondering if I am doing this PHP correct. I am almost 100% is right and should be working. Here is the code:
if($url == '/user/view.html.php?user_id='. $_GET['user_id'].') {
I was wondering if the $_GET part was correct. Is the PHP above correct?
You don't need the second tick. You're done concatenating after your $_GET statement it looks like.
if($url == '/user/view.html.php?user_id='. $_GET['user_id']) {

Categories