Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Adding a Contact Form Working with Get Variables

Jeff Styles
Jeff Styles
2,784 Points

header("Location: contact.php?status=thanks"); If "status" is a variable why is there no preceding dollar sign?

I thought all variables in php began with $....

3 Answers

In php you do indeed always indicate variables with the $-sign. This is quite unique to php. Variables in Java for example don't need any prefix like that.

The variables that you send over HTTP have nothing to do with php though, and it's important not to confuse that. HTTP and php are completely different things and entirely abstract from eachother. As you probably know, the former is a protocol for how HTML should be sent over the web, while the latter is a programming language.

If you want to read up on the HTTP methods GET and POST, you can do so here: http://www.w3schools.com/tags/ref_httpmethods.asp.

GET and POST are the 2 most popular methods, but there are others too, but you probably won't use them much unless you dive into RESTful applications, such as Laravel.

Good luck!

Kevin Korte
Kevin Korte
28,111 Points

Yes agreed, in that case you're not setting a PHP variable, you setting a variable in an HTTP query string, which has a different set of rules and standards to go by.

PHP can read query string variables using the $_GET variable that Randy showed you.

Because it will be in a URL, and in the a url a variable doesn't use the $ sign.

Everything, after the ? becomes a variable and values.