Placeholder Image

字幕表 動画を再生する

  • So let's talk about redirecting a Web page using PHP, so this could be a valuable thing for any number of reasons.

  • So basically, the idea is you have a domain and you have a Web page, and what you want is we want people to go to that Web page, and then you want them to get automatically redirected somewhere else.

  • Maybe this is for maintenance, So let's say you're doing maintenance on your website so you don't people calling your website.

  • So for the index they will come to, let's say, still condo show dot com and then will automatically get redirected somewhere else so that you could do maintenance.

  • This can also be very valuable for things like tracking.

  • So let's say you're doing some kind of affiliate link.

  • Or basically you're selling like cost per click advertising.

  • So instead of using a girl shorter like Bentley or something like that, what you can do is you can come up with Web pages on your own site and then have a simple PHP script that redirects people to a different Web page against her like some kind of affiliate landing page.

  • But while it did does that It can also do things such as track how many times your Web page has been accessed, take information from the people accessing the Web page, so on and so forth.

  • And so this script could be very valuable for any number of reasons.

  • And it's a very simple way that basically just redirect people when they come to your Web page.

  • You then redirect them to a different Web page, and it's relatively seamless for the end user.

  • But it allows you to do things again, like log information.

  • So log how many times Web page has been access along the I p addresses of people, the access of the Web page log, things like Web browsers, all kinds of different information.

  • Um, and so that's why we're gonna show you how to do in the script is using the header to redirect people to a different Web page.

  • So with that, let's go over, and I'll show you how this very, very simple script actually works.

  • So this is a simple script called header dot PHP and all this is going to do is is going to redirect people from the header dot PHP page, and we're just going to send them to our friends, Our friends over at CNN dot com s so I'm gonna do is I'm gonna upload this to silicon dojo dot com.

  • So So silicon does dot com forward slash header dot PHP.

  • When we go to that particular you Earl, it will automatically redirect us to CNN dot com.

  • And so for this you could basically put almost anything in here.

  • I could put in a lot of Peter guy dot commer feel normal dot com or whoever Whoever else again like that, you can put in like a landing page to an affiliate site.

  • Since this is all a PHP script, all I'm doing in this particular script is I'm simply sending somebody to to the page.

  • But I could have again a connection to a log file here.

  • I could drop cookies.

  • That's one thing people do in order to track people through the Internet.

  • I could do a redirection, but before I do the redirection, I could drop a cookie and the Web browser so I can track them through multiple sites.

  • So the important thing is is what you could do is you can add in a lot of other PHP functionality before the redirection actually happens.

  • And as far as the user is concerned, it will be almost instantaneous.

  • And they won't even realize that other functions have happened before they got redirected.

  • But for this, as always, it's really simple.

  • Just you open with the open the PHP tag, and then we're going to use what's called a header function.

  • So the header function can actually send different types of information and back to the Web browser.

  • What we're simply going do here is we're going to use the head or function as a redirect, and so we're gonna do is you're going to say Header and they were going to open parentheses.

  • Now this gets a little weird.

  • As faras I just conventions go.

  • This looks kind of odd, but everything within the parentheses is important for the redirect, so don't leave anything out.

  • So what first thing that we're gonna do is we're gonna open with a double quotation marks, and then what we're going to say is, we're going to say location, and so this is important.

  • This has to be here.

  • So location, uh, colon.

  • And so what?

  • This is saying to the two the browser is.

  • I want you to go to this location.

  • Then you're gonna do a space, and then you have to type out the entire fully cool, qualified domain names.

  • So the a t t p colon forward slash forward slash and then the entire Web address you're gonna be going to.

  • And so for this, it's just www dot CNN dot com and just plug in that forward slash.

  • So what this is going to say is returned header.

  • So give back to the Web browser, a new locations of the location of and then wherever you're sending them www dot CNN dot com and then you close out the double quotation marks past that.

  • You close the parentheses and then, of course, you do the semi colon, and that's the sum total of what's required in order to do a redirect using Ph.

  • P.

  • Of course, we then close the pH be script, and that's it.

  • So it's important to understand with this, this is all you have to do for the header.

  • But again, you have a kind of a lot of other functionality.

  • Fire off before they actually get redirected.

  • You can grab their I p address, you could drop it a cookie.

  • You can do all kinds of wacky stuff.

  • And so again, that this becomes very valuable for, like, Web marketing, e commerce, advertising, any kind of stuff like that.

  • Then what we're gonna do is we're gonna go to Google Chrome and show you how this works.

  • We're going to go to Silicon, does joe dot com and then we're simply going to put in header dot p a p So again, to be clear here, we're going to silicon does oh dot com This is this is my This is my website is my domain name.

  • Well, we hit enter, you want to see relatively quickly.

  • It's simply fires off and we get redirected to CNN dot com.

  • And so that's how it could work.

  • So I could have again I could have Eli critter god dot com forward slash nord VPN dot PHP.

  • If you want the Nord VPN, then that would automatically send you to my Nord VPN affiliate page Or, you know, a lot of computer guy dot com.

  • Forward slash better health dot PHP.

  • I could do it, I suppose, and then that would send you directly to my better help affiliate pig.

  • And the nice thing about this is I completely owned this.

  • This is not this is not somebody else's u r l Shorter.

  • I have to worry if it's getting shut down.

  • It's not somebody else's service where I have to worry again.

  • I have to worry about what information there grabbing from my users.

  • I completely owned this, and this is all literally within PHP.

  • So it's not like it's gonna get deprecate ID in a year or two like this will be around forever.

  • So that's basically all there is to the, uh, to redirecting with with the header function.

  • Ah, and again it really is that simple.

  • So that's all you have to do to redirect Web pages using PHP because use that header function, you just do header parentheses, double quotation, mark, location, colon and then wherever you want to send the person.

  • Ah, and that's basically all there is to it.

  • This is an incredible, useful tool.

  • Again, this is This is where I talk about, like that kind of secretarial service that PHP can d'oh!

  • We're just a simple thing where let's say you know you had an old website that you no longer want to maintain and you want to send people to your new website.

  • All you do is on the index dot PHP file that you create.

  • You literally just put this header script in, and that will send people to your new website.

  • That's all you have to do.

  • Easy peasy.

  • Also again, like, say, with e commerce, that type of thing you can read right people to particular affiliate landing pages.

  • That type of thing makes life a lot easier.

  • And again, with with great power comes great responsibility.

  • You can see with us where, if you start adding on some of the other functionality of showing you showing you with PHP, you can start doing either some good or nefarious things again.

  • Multiple multiple lines of code can fire off before the person actually gets redirected so you can grab their I P address.

  • You can grab their Web browser.

  • You could drop cookies in.

  • You can do all kinds of funky stuff.

  • And again, remember, morals, morals and ethics are a good thing.

  • Just just gonna put that out there for you.

  • Be a good person when you code that's that would be my only request.

  • And so that's all there is for redirecting using the header function, and that's really how easy it is, and that's why it matters.

So let's talk about redirecting a Web page using PHP, so this could be a valuable thing for any number of reasons.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

PHP - ウェブページをリダイレクトする - header() (PHP - Redirect Web Page - header())

  • 8 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語