Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Request, New Page and - Hey, You Welcome Back!

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Request, New Page and - Hey, You Welcome Back!

Hi there! I knew you’d be back! Learning to be a PHP programmer is a lot of work, but totally worth it. So, keep going: you’re getting more dangerous with each minute you spend practicing.

Getting the Code, Starting the Web Server

We’re going to keep coding on the project from episode 1. If you don’t have that code, just download it from the screencast page and unzip it. Once you’ve done that, we just need to start the PHP web server.

Open a terminal and move into the directory where the unzipped files live. I already unzipped the files in a Sites/php directory. Start the PHP web server by typing the following:

php -S localhost:8000

Great! Now just put that URL in your browser and voila!

Tip

Having issues? Check out our server setup chapter in episode 1!

What Secrets lie on the HTTP Request?

In episode 1, we learned that the web works via requests and responses. Our browser sends an HTTP request message into the interwebs for airpup.com/contact.php. This eventually finds our server where it scratches on the door. And with any luck, some web server software like Apache will be listening, open the door, look in a certain directory for the contact.php file and process all the PHP treats . . . I mean tags. The final HTML is called an HTTP response, and is sent from the server back to our browser.

So it all starts when we send that HTTP request message. But actually, that message has a whole lot more information than just the hostname and page we want. It also has our IP address, info on which browser we’re using and the values of fields when we submit a form.

Peeking at Requests

Let’s peek at these by going to the debugger on our browser. Click on the network tab and refresh.

Tip

You may need to enable network tracking before refreshing, which the network tab will ask you to do. If you don’t see any debugging tools, make sure you’re using a good browser. I recommend Google Chrome.

Each line here is an HTTP request that was just made by our browser. The top is the request for contact.php. The other requests are for the CSS, JS and images on the page. Yep, on every page load, your browser is actually making a bunch of requests into the internet tubes.

If you click on contact.php, we can actually see how this HTTP request message looks. Yep, it’s a lot of stuff. That User-Agent is what browser you’re using and Accept-Language is how the browser tells the server what languages you speak. It’s not important now, but we can get any of this information from inside PHP!

We need a New Page!

I want to build a form so a user can rent out their pet’s love to others.

Let’s start by creating a new page. How do we do that? Just create a new file called pets_new.php and scream some text out:

HI I AM A PAGE!

SQUIRREL!

To see us screaming at us, change the URL to /pets_new.php:

So every new page is just a new file. In a future episode, I’ll teach you a way to create URLs and pages that’s much fancier than this. But don’t worry about that quite yet.

Let’s make this page properly fancy by copying in the header.php and footer.php require lines:

<?php require 'layout/header.php'; ?>

HI I AM A PAGE!

SQUIRREL!

<?php require 'layout/footer.php'; ?>

Refresh to see a page that is only a little ugly. Progress! And a little Twitter Bootstrap markup makes this look a tiny bit better.

<div class="container">
    <div class="row">
        <div class="col-xs-6">
            <h1>Add your Pet</h1>
        </div>
    </div>
</div>

Leave a comment!

2
Login or Register to join the conversation
Mahmoud M. Avatar
Mahmoud M. Avatar Mahmoud M. | posted 3 years ago

Hello,
I downloaded the project and tried to add the Pets_new.php file using "visual Studio code" Editor, but it is saying there is no permission to add new file ..?
this part is not clear in the lesson, which and how to use the code editors ?
that's why I tried the "Visual Studio code", if there is something better or easier just please advice and I will use it

Thanks,

Reply

Hey Mahmoud M.

Hmm, that's odd, you may have to check your file/folder permissions on your project, seems like your editor can't create files under your project's folder?. About editors, I would recommend you to use PHPStorm, is the best PHP editor by far

Cheers!

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

userVoice