It has been a while since I've been thinking over this feature that some websites are implementing and it looks to be very successful.
Websites like tumblr.com, blogger.com, wordpress.com allow users to register new sub-domain names from within the website by using a simple HTML/PHP form. With my current knowledge of PHP I couldn't figure out myself how this is done. I've read some posts on this and still can't build a clear idea about this.
So, how do I create a script that allows users to register their own sub-domains on my website (www.username.mydomain.com) and more than that, how do I allow them to use a different website template (as wordpress.com does). Is this possible to be done on a shared server or a dedicated server is needed?
These subdomain issues are brought down to the level of nice URLs, friendly URLs etcetera, as this feature has various names.
Basically what you do is that you set up a redirection so that if someone enters foobar.example.org, the server will serve example.org/user.php?name=foobar or example.org/foobar. After this, it's only a matter of how you put together your PHP script so that user.php or the contents of /foobar is parsed properly. The "registration" part is statically done in the .htaccess file in your DocumentRoot.
Of course this will need some sort of proper error handling for a nonexistant "subdomain".
I can tell you a simple approach.
First you have to enable subdomains in your domain. You can search for 'wildcard-dns and sub domains'. Next all is programming logic.
While registering you can ask for a unique subdomain name. After login, redirect it to the registered subdomain.
It's easy to create the wildcard subdomains. Check my post for create the wildcard subdomains dynamically in Create subdomains on the fly with .htaccess (PHP) .
How to Create Dynamic Subdomain with the help of PHP and Htaccess
We can create dynamic sub domain like top websites who provides us sub domain access with the help of username, I will try to give the best solution for the programmers. I am going to explain how to use htaccess with PHP to create dynamic sub domains, using this you can easily host multiple sub domains on single server.
Process to create dynamic subdomain
Add zone record in domain name setting
Open the setting of your Domain name provider and go to your domain DNS(Domain Name Settings), click add zone record.
Create A record and Point to IP
Now you need to create a custom A record for all your subdomains.
Select A record, HOST * POINTS TO: Your IP Address
Example : 102.30.138.121
Create a record and point to ip prashantabhishek.com
Repeat the same for host #.
Create dynamic subdomain by Prashantabhishek.com
Add CNAME record
HOST www points to # (this refers towards your IP address. )
dynamic sub domain c name record
Save the setting and enjoy the code effect.
Read more at : https://www.prashantabhishek.com/blog/view-post/how-to-create-dynamic-subdomain-with-the-help-of-php-and-htaccess/
Related
Sorry if the question will seem little fuzzy and you will be tempted to down-vote it as soon as you read it. I am far from being an expert in system administration but I will try to explain the problem as clearly as I can.
I need to create a website where users can have profiles and attach an external domain to their profile page on this site. Let's say we have a site:
myresume.com
User will register and create a profile and his url will look like:
myresume.com/username
The feature I need to add should enable user to point his domain to his profile url.
Is it possible via php as my whole application will be written in laravel 5.2?
I will probably need to have my nameservers or just give user the IP address which he needs to point his domain to but then I will need to fetch the domain from my side somehow and point it to the url (myresume.com/username). How can it be done?
If someone could give an explanation how it is done or at least point where to search for an answer it would be amazing. Thanks.
You need to know how Apache NGINX works.
You need to know what $_SERVER['HOST'] is.
Logic to implement this.
This is how you will do it:
Host your app on a VPS / dedicated where your app is the 'default' with no other VirtualHost.
On your index.php file, define URL. If URL is set, let your Laravel's route choose which profile_id is matched with URL and then redirect the user to that URL or render the output.
Simple?
I am setting up a SaaS application written in PHP. Now every user gets a subdomain.appname.com where subdomain is user's choice. So there can be subdomain1.appname.com, subdomain2.appname.com and so on.
I have setup the CNAME entry too as a user's domain so that subdomain1.customerdomain.com points to subdomain1.appname.com and when I try subdomain1.customerdomain.com it perfectly loads the subdomain1.appname.com with subdomain1.customerdomain.com in the address bar.
As soon as I hit any link in the app, the domain in the address bar changes to subdomain1.appname.com which is obvious because there is no htaccess rule yet. And that's where I need help..I suck at htaccess, so what should be the htaccess file like to handle domain masking and keeping user's domain in the address bar all the time.
No, the problem here is not .htaccess, the problem are the links.
The application must output all links using the hostname actually used in the URL. It must not use a fixed application URL, but determine it dynamically.
I need to build a strategy or plan for implementation of a site
the situation is the following:
i have a site for people which belong to a community say xyz.
now i need to provide an account for the individuals of such communities on my site
when they logs into my site, there will be a feature to build a portal for themselves with some functionalities
like wise when n no of people logs in they might create n no of portal for themselves with some functionalities
the people will also create or use a n no of domain name respectively for the portal.
my problem or questions is:
How can i plan to create such a website?
Do i have to create separate code base files for each individual portal? or my current website portal code base can serve for each individual created portals?
How can i setup the site at domain automatically?
Update 1
I think the main website will already have a domain name for it
The other portals created through the main website will also have domain name for themselves as they are for some users
but the question is i have my main website domain name already using the code base which is serving the main website, now can i create domain names through my main website for the users and also ask the newly created domain names to use the same code base of my main website?
Actually i am planning to create domains through my application(please guide how can i create domain from my application) than after creating the domain can i ask the newly created domain to use the code base of my website which created the domain.
than there in the code base i do a domain name check as suggested in few other forums i guess, and load the content for the portal in the newly created domin
is this possible? if yes also can you guide me how can i:
create domains from my application? and than
during domain creation process through my application, how can i configure the new domain being created to my application code base?
is this the right way of implementing it?
1) How can i plan to create such a website?
Think about what exactly it is that the user requires. They have made an account, and want a portal to their own personal domain on the server. A domain on a server is just a file, so when they create that new portal, you might want to simply add a new HTML file under a logical directory, and populate it with some standard HTML.
2)Do I have to create separate code base files for each individual portal? or my current website portal code base can serve for each individual created portals?
I guess you can make the difference specified by a query string in the URL. For example, add database values for each user, and do something like this:
www.mywebsite.com/portal.php?id=40395
Your page will then use that id value, and take values from the database to populate the page with. That way you only have one file, portal.php, but it serves for any number of people.
3)How can i setup the site at domain automatically?
Like I said, the domain is just a file on the server. For example:
www.mywebsite.com/files/directory/hello.php
is just referring to the structure of files on the server. Namely:
www.mywebsite.com
files
directory
hello.php
If you place a file, goodbye.php in the same place, you can access it in a similar way.
www.mywebsite.com/files/directory/goodbye.php
PLEASE NOTE : You have provided no code, so I don't feel obliged to provide any in return. If you haven't took a swing at the problem of implementing the solution, then I guess I won't either.
Use Case: I am working on an application where user can build his own html template and publish it to his domain by selecting one. He can use different components to do this.
Issue: I want to transfer the pages build by the user from my domain to his created domain. Something similar to what is done here. Now currently in the prototye, what I do is write the content to a file (a .html file using ajax request) then make an FTP connection to the users domain (possible beacuse domains are created dynamically by the application) and transfer the files to his domain.
This, I believe, cannot be the right way and I would like to build it around a REST service which would make it flexible and also secure.
Research: I went through the web and found some website handle this very well (like the one mentioned above) and believe they have built it as a service. Am I on the ?
I would like suggestions and the possibilities so I can move forward. I am using PHP on the server side and javascript on the client side.
I can see some possible features to add safety to your services :
Check the source IP from the request, and only allow your servers to make the REST calls.
add header('Access-Control-Allow-Origin: *'); with the list of the possible domains to make the calls, instead of the *.
add security tokens related to the caller machine IP address, that would work as a password for the machine.
send all the data using post instead of get.
To update the page, I would go this way :
keep the data in the database, on server 1
add a page that reads from the database the content of the page based on a domain parameter
on the domain page call server 1 with the domain parameter to get the contents
Use Case:Working on a project where user can create his own site and publish it to internet.(Something similar to this or this). The user can create and later edit his website.When the user wants to publish we create a domain of his choice(a subdomain at first.Can be a different domain later).
Issue:What we want to do is,have the images stored directly on the domain created for the user(The domain initially would be created as a subdomain).For example,our site is at www.xyz.com,then the subdomain can be ABC.xyz.com.This will help to maintain a single copy of images for both the publish and the edit domain.We don't want to store the same image at two different locations.
Research:
Two possibilities that I found could be used:
1) Have a php upload script(upload.php) on each domain created that would be called when user uploads any image.-->Not sure how efficient it would be
2) Use FTP to transfer images from a domain to another.(Some cross domain mechanism)-->Not sure about the security issues here
Do I need to have any kind of cross domain script to be written?Please,help me with how to go about the issue.I don't want the entire code but the logic that would take me in the right direction.Suggestions,if my approach is wrong are welcome.Thank you for your time.
Note: I am still figuring out other alternatives.If I get my code in some shape,will update it.