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 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,148 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.