MOBILE USERS: m.isthmus.com
Connect with Isthmus:         Newsletters 
Thursday, December 18, 2014 |  Madison, WI: 22.0° F  Overcast
Collapse Photo Bar

Oy, PHP code junkies, here's one for ya

Wiis, PlayStations, iPads, blogging platforms, Facebook and anything else worthy of buzz in the digital world.

Would you rather be writing code or drinking?

Writing Code
0
No votes
Drinking
7
100%
 
Total votes : 7

Oy, PHP code junkies, here's one for ya

Postby Entropy's Stagger » Wed Nov 10, 2004 9:52 pm

Alright, here's the current code. This is in a index.php file at the front end. .php files are the first recognized on an Apache server. The second in line works. Why doesn't the first line? What's missing in between? Or what should go away in between?



<? $refer=$HTTP_HOST; if ($refer== "www.domainname1.com"){ header ("Location: ./domainname1.html"); }else header ("Location: ./index1.html"); ?>

<? $refer=$HTTP_HOST; if ($refer== "www.domainname2.com"){ header ("Location: ./domainname2.html"); }else header ("Location: ./index1.html"); ?>



The goal here is, the server doesn't offer domain name redirection. The idea is, when someone types in www.domainname1.com, it'll send them directly to the appropriate .html page. Or when someone else types in www.domainname2.com, it takes them to the other approriate .html page. Both .html files are in the same public_html folder on the server.

What the hell am I missing here?
Entropy's Stagger
Forum Addict
 
Posts: 445
Joined: Tue Jul 20, 2004 1:37 pm

Postby Entropy's Stagger » Fri Nov 12, 2004 4:22 pm

Alright, after many glasses of brandy and coke, I figured it out. Chuck Schick, you'll probably be the only one who will appreciate this.

<? $refer=$HTTP_HOST;

if ($refer== "www.domainname1.com"){ header ("Location: ./domainname1.html"); }

else

if ($refer== "www.domainname2.com"){ header ("Location: ./domainname2.html"); }

else header ("Location: ./index1.html"); ?>

I've expanded the lines for clarity. I've found you can add as many 'if' lines you want so long as the 'else' precedes it. This also can correct the problem of someone typing only, domainname1.com in the address bar. What happened in the past with this code was when someone didn't put the www before the url, it would redirect them to the ./index1.html page. Which was bad because instead of them going to the site for kids, they ended up at the porn site. So I simply added yet another if line with only ($refer== "domainname1.com") in the line and it works.

Ok, now for a celebration drink. . .
Entropy's Stagger
Forum Addict
 
Posts: 445
Joined: Tue Jul 20, 2004 1:37 pm

Postby Chuck_Schick » Fri Nov 12, 2004 4:56 pm

Entropy's Stagger wrote:Chuck Schick, you'll probably be the only one who will appreciate this.

I may be. And I do.

I totally should have caught the syntax error too, as if/else is a common construct. D'oh ....

Salut!
Chuck_Schick
Forum God/Goddess
 
Posts: 10385
Joined: Fri Nov 16, 2001 4:41 pm
Location: back atcha

Postby Entropy's Stagger » Fri Nov 12, 2004 5:07 pm

Salut!

I guess the only thing that needs to be mentioned here if anyone else wishes to make use of this code is that on my server, the index.php file is the first recognized. This may vary from server to server. Some servers recognize the index.html first.

Either way, I'm glad that's over.
Now, go listen to BZT.
Entropy's Stagger
Forum Addict
 
Posts: 445
Joined: Tue Jul 20, 2004 1:37 pm

Postby Bruno » Mon Nov 15, 2004 5:27 pm

Why isn't there an option for drinking as we write code? :wink:
Bruno
Forum God/Goddess
 
Posts: 1217
Joined: Sun Mar 30, 2003 6:32 pm
Location: Sector 7G


Return to Technology & Video Games

Who is online

Users browsing this forum: No registered users and 1 guest

moviesmusiceats
Select a Movie
Select a Theater


commentsViewedForum
  ISTHMUS FLICKR
Created with flickr badge.

Promotions Contact us Privacy Policy Jobs Newsletters RSS
Collapse Photo Bar