Home | Community | Message Board

Mycohaus
This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Shop: PhytoExtractum Buy Bali Kratom Powder   North Spore Cultivation Supplies

Jump to first unread post Pages: 1
Invisibledaytripper05
Psychonaut
Male User Gallery


Folding@home Statistics
Registered: 10/30/06
Posts: 6,962
Loc: In my garden
Forwarding a sub domain & MISC php question
    #8647677 - 07/17/08 03:49 PM (15 years, 7 months ago)

I am using Brinkster for a particular website. On the sites I host myself, I can just goto godaddy.com and they will forward the URL with their DNS.

So... Brinkster setup a sub domain http://secure.someurl.com and I want it so when someone visits this sub domain they are redirected to https://someurl.net.

Brinkster said they could setup the sub domain but I would have to do the redirect via code. PHP is my server side language of choice and know the syntax for redirecting a URL but not a query to a specific sub domain.


Edited by daytripper05 (07/17/08 04:44 PM)


Extras: Filter Print Post Top
Invisibledaytripper05
Psychonaut
Male User Gallery


Folding@home Statistics
Registered: 10/30/06
Posts: 6,962
Loc: In my garden
Re: Forwarding a sub domain & MISC php question [Re: daytripper05]
    #8647976 - 07/17/08 04:50 PM (15 years, 7 months ago)

I have another unrelated question but didn't want to make a new thread.

I have a data entry form with 17 data fields for a medical equipment company. I need to validate the form. So far, I have a way I would do it but that might not be the correct way.

I have come across the preg_match function to be honest, it's confusing and most sites a few vague explanation of the syntax. But before delving a little deeper and wasting more time, I just didn't know if this is a good way to validate a form.

How would you validate a form with first&last name, address, phone number, zipcode? I could obviously test each and every field but it seems after doing a couple quick searches the preg_match function comes up.


Extras: Filter Print Post Top
InvisibleDiploidM
Cuban


Folding@home Statistics
Registered: 01/09/03
Posts: 19,274
Loc: Rabbit Hole
Re: Forwarding a sub domain & MISC php question [Re: daytripper05]
    #8647978 - 07/17/08 04:51 PM (15 years, 7 months ago)

You don't need PHP. HTTP has this functionality natively. If my failing memory is right, just put this in your HTML file and you're done:

Code:

<html><head>
<meta http-equiv="Refresh" content="0; url=http://www.some_place_else.com/">
</head></html>



The content=0 part is how long, in seconds, the browser will delay before loading the new page. A 0 means it will immediately load the next page.


--------------------
Republican Values:

1) You can't get married to your spouse who is the same sex as you.
2) You can't have an abortion no matter how much you don't want a child.
3) You can't have a certain plant in your possession or you'll get locked up with a rapist and a murderer.

4) We need a smaller, less-intrusive government.


Extras: Filter Print Post Top
OfflineYthanA
ᕕ( ᐛ )ᕗ
Male User Gallery


Registered: 08/08/97
Posts: 18,793
Loc: NY/MA/VT Borderlands Flag
Last seen: 26 minutes, 27 seconds
Re: Forwarding a sub domain & MISC php question [Re: daytripper05]
    #8647984 - 07/17/08 04:52 PM (15 years, 7 months ago)

This should do it:

Code:
if ($_SERVER['HTTP_HOST'] == 'secure.someurl.com'){
header("Location: https://someurl.net{$_SERVER['REQUEST_URI']}", 301);
}



Edit: damn, beat to the punch and I also might have misinterpreted what you meant by "redirecting a URL but not a query".


Extras: Filter Print Post Top
OfflineYthanA
ᕕ( ᐛ )ᕗ
Male User Gallery


Registered: 08/08/97
Posts: 18,793
Loc: NY/MA/VT Borderlands Flag
Last seen: 26 minutes, 27 seconds
Re: Forwarding a sub domain & MISC php question [Re: daytripper05]
    #8648029 - 07/17/08 05:07 PM (15 years, 7 months ago)

If you want to ensure that your input matches a certain format, then preg_match is indeed the correct function to use. Here's a good regex guide, and to get you started here are some examples:

Validate a name (i.e. accept letters only):
preg_match('/^[A-z]+$/', $field);

Validate a phone number in formats 3334445555, 333.444.5555, 333-444-5555, 333 444 5555, (333) 444 5555, and all combinations thereof.
preg_match('/^\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}$/', $field);

Validate a zip code in 12345 or 12345-6789 format:
preg_match('/^\d{5}(?:-\d{4})?$/', $field);

I use RegexBuddy to help with regexes and I highly recommend it. Don't worry if regexes confuse you, they confuse everyone at first but eventually you will come to appreciate their elegance.


Extras: Filter Print Post Top
Invisibledaytripper05
Psychonaut
Male User Gallery


Folding@home Statistics
Registered: 10/30/06
Posts: 6,962
Loc: In my garden
Re: Forwarding a sub domain & MISC php question [Re: Ythan]
    #8648030 - 07/17/08 05:07 PM (15 years, 7 months ago)

I don't even know what I was trying to say there...reading that again, and it doesn't even make sense to me.

But no less, you answered my question.

EDIT:

except what does this mean. "{$_SERVER['REQUEST_URI']}", 301);"


Extras: Filter Print Post Top
OfflineYthanA
ᕕ( ᐛ )ᕗ
Male User Gallery


Registered: 08/08/97
Posts: 18,793
Loc: NY/MA/VT Borderlands Flag
Last seen: 26 minutes, 27 seconds
Re: Forwarding a sub domain & MISC php question [Re: daytripper05]
    #8648552 - 07/17/08 08:23 PM (15 years, 7 months ago)

$_SERVER is an array which is auto-populated by PHP with certain variables pertaining to the server and the current request. $_SERVER['REQUEST_URI'] is basically the string following the domain name. If someone goes to http://www.someurl.com/script.php?var=1&blah=2, then $_SERVER['REQUEST_URI'] will contain '/script.php?var=1&blah=2'. So in my example it forwards you to the same URL you requested, just on a different domain. The curly brackets are necessary when you want to include an array within a string, it could also be written as "Location: https://someurl.net".$_SERVER['REQUEST_URI'] (the period serves as a concatenation operator). Or you could do $uri = $_SERVER['REQUEST_URI']; header("Location: https://someurl.net$uri"); because then $uri is a variable, not an array.

The 301 means to give an HTTP 301 status code which means "moved permanently". It's not strictly required, as the location header is enough to forward the browser. But for web spiders and such it tells them to go directly to the new URL and bypass the old one in the future. 307 is a temporary redirect, which you can use if you may change the redirect and you want spiders to always go through the original page first.


Extras: Filter Print Post Top
Jump to top Pages: 1

Shop: PhytoExtractum Buy Bali Kratom Powder   North Spore Cultivation Supplies


Similar ThreadsPosterViewsRepliesLast post
* misc. Linux questions monoamine 1,024 10 07/07/04 01:41 PM
by MAIA
* PHP? Crazy! TinMan 1,108 7 09/11/03 10:44 AM
by 3DSHROOM
* Buying domain names; owning a website 3eyes 616 3 11/22/04 09:02 PM
by AhronZombi
* . dr_gonz 919 5 01/17/05 09:41 PM
by gema
* Question about transfering a domain runnerup 364 0 01/05/05 06:24 PM
by runnerup
* Please help me today I registered my first domain *DELETED* T0aD 1,361 10 12/24/02 02:27 AM
by T0aD
* Did the Shroomery lose a domain? Mister Black 4,152 10 02/02/03 12:11 PM
by Xibalba
* Registering a domain name anonymously? oscill8 1,794 2 06/04/01 02:49 PM
by shroomies

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: trendal, automan, Northerner
809 topic views. 0 members, 0 guests and 1 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2024 Mind Media. Some rights reserved.

Generated in 0.026 seconds spending 0.008 seconds on 14 queries.