When we add a valid data to the new article farm and submit it a new article is inserted into the database
and its I.D. is displayed at the moment.
Oh.
We're just read displaying the farm which includes all the data.
We just insert it so we could keep submitting this farm adding more Ricardos it would be more user friendly
that way to redirect to the article page where we could see the new rijkaard we just insert it.
Normally a user requests a page by typing in a u r l.
Clicking on a link are submitting a form the server receives the request and sends back a response.
For example a page of h.t. Mail.
Sometimes though instead of replying with some content the server replies with a message to tell the
browser to request a different you are L..
This is known as a redirect.
It's common to redirect to another page after inserting some data into a database for example
when a web server responds to a request through your email and sends a file to a browser along with
the file it sends some additional information about it.
Details of the server the type and status of the response and so on.
These are kalid response headers because they're sent before the actual content of the page.
We can see the response headers by using developer tools in the browser.
To redirect to another eurail we send a header which comes in the response headers to tell the browser
to request another you are L..
To do this in p s p we use the header function and we pass in a string that contains the Eurorail of
the page to redirect to now a new article script.
At this point we've just inserted the rijkaard and we have it side.
So here we can use the header function to redirect to the article page passing in the U R L of that
page which includes the idae in the query string as the browser is going to redirect at this point.
It's good practice to our ways exit the script after sending a redirect header like this.
None of the code following this is going to be seen in the browser so it's better not to even execute
it.
Let's give that a try.
If we enter some data and submit the farm the record is inserted and we have redirected to the article
page where we can see the new rijkaard
we can see the location header here that the server sent to the browser which is what caused the redirect.
Here we are redirecting to a relative to our L..
In other words the Eurorail is relative to the current one.
The same server same directivity and so on.
This works in modern browsers but might not work in older ones to make sure this works everywhere.
We should be using an absolute u r l which is one that contains the protocol and the server name.
Instead of hard coding the server address in our code we can get this information from data provided
by this server super global.
First we need to get the protocol which we can do using this piece of code without going into this in
too much detail.
This is the standard way of checking if the server is using H T T P R H T T P S we can get the server
name using the H T T P host element from the server.
Super global.
So using these we can now redirect to an absolute.
You are real.
Let's give this a try.
When we submit the farm with some data we're redirected as before and if we look at the headers we can
see the location header is now an absolute u r l and we've artier magically included the protocol and
server name without hard coding them.
So now when we add a new article we're redirected to the individual article page.
Finally instead of having to type the uml for the new article page let's add a link to the index page
here like that.
Now we can click on this link to get to the new article page.