Asked  7 Months ago    Answers:  5   Viewed   51 times

How do I create subdomain like http://user.mywebsite.com ? Do i have to access htaccess somehow? Is it actually simply possible to create it via pure php code or I need to use some external script-server side language?

To those who answered: Well, then, should i ask my hosting if they provide some sort of DNS access??

 Answers

81

You're looking to create a custom A record.

I'm pretty sure that you can use wildcards when specifying A records which would let you do something like this:

*.mywebsite.com       IN  A       127.0.0.1

127.0.0.1 would be the IP address of your webserver. The method of actually adding the record will depend on your host.


Doing it like http://mywebsite.com/user would be a lot easier to set up if it's an option.

Then you could just add a .htaccess file that looks like this:

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^([aA-zZ])$  dostuff.php?username=$1

In the above, usernames are limited to the characters a-z


The rewrite rule for grabbing the subdomain would look like this:

RewriteCond %{HTTP_HOST} ^(^.*).mywebsite.com
RewriteRule (.*)  dostuff.php?username=%1

However, you don't really need any rewrite rules. The HTTP_HOST header is available in PHP as well, so you can get it already, like

$username = strtok($_SERVER['HTTP_HOST'], ".");
Wednesday, March 31, 2021
 
Webroots
answered 7 Months ago
13

You can set the value to "None" using ini_set. There's no check that the value is supported when that function is used:

ini_set('session.cookie_samesite', 'None');
session_start();

session_set_cookie_params can also set it:

session_set_cookie_params(['samesite' => 'None']);
session_start();

The bug report for this to be supported in php.ini is here.


As @shrimpwagon said in a comment below, session.cookie_secure must be true for this to work. PHP doesn't require it, but browsers do.

Wednesday, March 31, 2021
 
mcography
answered 7 Months ago
97

I am not sure if this is something you might be interested in, but you could always create a new subdomain and call it something like style.[domain] and create a new variable in your config file and point it to that. this way you have all the images and css files etc stored in one place and if your traffic spikes you can always move that subdomain to a CDN etc so its really customizable.

UPDATE

ok so you can simply use a new variable in your config file like below :

$_config['http'] = 'http://www.yousite.com/';

now you can just use this variable to point to all your downloads etc on the main site rather than each pointing to the subdomain's folder. and if you want to be more flexible you can also add a few more css or js folders like :

$_config['http'] = 'http://www.yousite.com/';
$_config['css'] = $_config['http']."css";
$_config['js'] = $_config['http']."js";

the solution above will also help you if you decided to move the files around or just move a certain folder around etc. this is a good practice if you can adopt it.

Saturday, May 29, 2021
 
Tak
answered 5 Months ago
Tak
92

After five hours of trying myself, I finally contacted my hosting provider and they had a look.

The verdict? session.save_path in php.ini had not been set. The script above is now running properly.

If someone cares to elaborate on the whys and hows and whatnot, I'll be happy to give them the solution, otherwise I'll have to accept my own.

Saturday, May 29, 2021
 
fillobotto
answered 5 Months ago
27

I suggested in my comment that you could make your own custom script to launch Eclipse. Even in a way that the same script may serve for every user:

/opt/eclipse/eclipse -vmargs -Djava.io.tmpdir=/tmp/eclipse/$USER
Saturday, August 28, 2021
 
user9891428
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :