Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Basic PHP Website (2018) Building a Media Library in PHP Working with _GET Variables

Hasan Can Terzi
Hasan Can Terzi
5,892 Points

INPUT_GET instead of $_GET

Hello everyone, If you had a trouble about $_GET You should use INPUT_GET. I am using NetBeans IDE and I took an error which is " Do Not Acess Superglobal $_Get Array Directly". Problem solve is in PHP docemantation:

http://php.net/manual/en/filter.constants.php

if (filter_input(INPUT_GET, "cat") == "books") { $pageTitle = "Books"; }elseif(filter_input(INPUT_GET, "cat") == "movies") { $pageTitle = "Movies"; }elseif (filter_input(INPUT_GET, "cat") == "music") { $pageTitle = "Musics"; }

1 Answer

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

You can use isset() or empty() to validate the superglobal such as

<?php
if(isset($_GET) && !empty($_GET)){
    // do something
} else {
   header("Location: index.php");
}
?>

I think the code examlple above will not show up the "Do Not Access Superglobal $Get Array Directly" error message :D

Hasan Can Terzi
Hasan Can Terzi
5,892 Points

How can I show my code like yours? Colorful :D

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

You can click on the Markdown Cheatsheet link for the reference. it contain like this

Markdown Cheatsheet
Markdown is a short-hand syntax for easily converting text to HTML. Below are some popular examples of Markdown formatting. For more examples reference Markdown Basics for a more detailed overview.

Links
This is an [example link](http://example.com/)

Code
Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

          ```html
          <p>This is code!</p>
          ```

Italic
Here’s a word that is *emphasized*

Bold
Here’s a word that is **bold**

Images
![alt text](/path/to/img.jpg "Title")

Unordered List
+ Candy
+ Gum
+ Peanuts