I creating CMS with function auto-creating subdomains
Example: user pressing button Create domain I adding subdomain name john to DB and creating folder domain.com/subdomains/john.domain.com now i need redirect this subdomain john.domain.com to directory domain.com/subdomains/john.domain.com
code web.php:
if (!function_exists('getSubDomain')) {
function getSubDomain($url)
{
$domain = $url = str_replace(Request::getRequestUri(),'', $url);
$url = str_replace('http:','',$url);
$url = str_replace('//','',$url);
$url = str_replace('www.','',$url);
$url = str_replace('domain.com','',$url);
$url = rtrim($url,'.');
$url = ltrim($url,'.');
if($url){
$user = ['john','barry','wells','cisco'];
if(isset(array_flip($user)[$url])){
return true;
}
}
return false;
}
}
Route::group(['domain' => '{sub}.domain.com'], function(){
if(getSubDomain(Request::url())){
//Here need redirect to folder.
echo "Subdomain";
exit;
}
});
Related
I want to dynamically call the page in the view index when pressed, how can I do it?
index.php a tags
<div class="menu-item">Contact</div>
<div class="menu-item">Send Message</div>
routes.php
get('/', 'index.php');
get('/contact', 'views/contact.php');
get('/message', 'views/message.php');
router.php
function any($route, $path_to_include){ route($route,
$path_to_include); }
function route($route, $path_to_include){
$ROOT = $_SERVER['DOCUMENT_ROOT'];
if($route == "/"){
include_once("$ROOT/$path_to_include");
exit();
}
$request_url = filter_var($_SERVER['REQUEST_URI'],
FILTER_SANITIZE_URL);
$request_url = rtrim($request_url, '/');
$request_url = strtok($request_url, '?');
$route_parts = explode('/', $route);
$request_url_parts = explode('/', $request_url);
array_shift($route_parts);
array_shift($request_url_parts);
if( $route_parts[0] == '' && count($request_url_parts) == 0 ){
include_once("$ROOT/$path_to_include");
exit();
}
You can set name for each route .
i didn't see your routers code so i can't say my opinion surly .
but you can keep your routes in an array and set a name for each route . then write a function that by the name of a route can find it's url
I am attempting to redirect example.com to subdomain.example.com using codeigniters (3) redirect($domain). But what I end up with in the browser address bar is base_url/$domain when all I want is $domain.
The controller is set to look at the url and determine if the user has visited without a subdomain. If that is the case they are redirected to a view that asks them where they are from. This data is then passed to the same controller with a $_POST telling it where they are from.
$this->load->helper('url');
$subdomain_arr = explode('.', $_SERVER['HTTP_HOST'], 2);
$subdomain = $subdomain_arr[0];
if ($_POST != NULL)
{
$post = $_POST;
$subnames = $this->sendy->subName($post);//returns subdomain
foreach ($subnames as $subname)
{
$sub = $subname->subdomain;
}
$subdomain = $sub;
$period = ".";
$domain = $subdomain.$period.$subdomain_arr[0].$period.$subdomain_arr[1];
redirect($domain, 'auto');
}
There are thousands of possible subdomains. I just need codeigniter to prepend the subdomain and reload the page so that the url appears in the browser address bar as subdomain.example.com.
Derp! I added http:// to the $domain var and now it works as expected. Sorry for the asshatery.
$subdomain_arr = explode('.', $_SERVER['HTTP_HOST'], 2);
$subdomain = $subdomain_arr[0];
if ($_POST != NULL)
{
$post = $_POST; //this is the library name
$subnames = $this->sendy->subName($post);
foreach ($subnames as $subname)
{
$sub = $subname->subdomain;
}
$subdomain = $sub;
$period = ".";
$http = "http://";
$domain = $http.$subdomain.$period.$subdomain_arr[0].$period.$subdomain_arr[1];
redirect($domain, 'location');
}
With the addition of the $http now the redirect works properly.
I have the following problem: I have a set of domains with the same url structure:
domain-a.com/london/
domain-b/london/
domain-c/london/
I want to do the following thing:
If you are on domain-a.com/london/, I want "related" links underneath pointing to domain-b.com/london/ and domain-c.com/london/
I want these links to appear automatically using the URL of the current page, remove the domain so that only the rest is left - in my example: /london/ and add the other domains in front of this.
I know I have to use echo $_SERVER['REQUEST_URI']; to get the rest of the URL but I don't know how to create a link using this function.
<?php
$url = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
function generateLink($url, $uri){
if(strpos($url,'domain-a.com') !== false){
$link = 'http://domain-b.com' . $uri;
return $link;
}else if(strpos($url,'domain-b.com') !== false){
$link = 'http://domain-c.com' . $uri;
return $link;
}else if(strpos($url,'domain-c.com') !== false){
$link = 'http://domain-a.com' . $uri;
return $link;
}
}
?>
Link
I have redirect page called get.php which contain the following code:
header('Location: '.urldecode($_GET['url']));
$url = (isset($_GET[url]) && !empty($_GET[url])) ? $_GET[url] : NULL;
if(empty($url)){
header('Location: http://www.example.com/404');
}
This link used for ref tracking. When I check logs, I found someone abused it with pointing to non-malware website ie.
http://www.example.com/get.php?s&url=http://i-am-malware.yes
How to prevent this abused and only accept within local domain.
try this one
$url = "";
if(isset($_GET['url']))
{
$url = urldecode($_GET['url']);
}
if($url=="")
{
header('Location: http://www.example.com/404');
exit;
}
else
{
$arr = parse_url($url);
if($arr['host']==$_SERVER['SERVER_NAME'])
{
header("Location:".$url);
}
else
{
header('Location: http://www.example.com/404');
}
exit;
}
I am trying to get URL path and to save it as variable...
$setURL = true;
$getDomain = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$getSubdomain = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if ($setURL === true) {
$result = 'http://'.parse_url($getDomain, PHP_URL_HOST) . '/';
echo 'get domain';
} else {
$result = 'http://'.parse_url($getSubdomain, PHP_URL_HOST).parse_url($getSubdomain, PHP_URL_PATH);
echo 'get subdomain';
}
$siteURL = $result;
So basically if I defined variable $setURL = true; it will return correct URL for simple domain ... http://domain-name.com
However else does not work as I want to... else is there for subdomains. So if I set $setURL = false; it should return following... http://domain-name.com/path/
But unfortunately it return more then that... It returns anything I type as URL...
http://domain-name.com/path/something/index.php it will return all of that as URL!
Please help me to fix this as I don't have any ideas how I could manage to make it.
Formally, a subdomain precedes a domain name. For example, in ftp.debian.us, ftp is the subdomain.
It sounds like what you want is the first path in the URI. You can use PHP's explode() method to grab the first segment in the path.
$uriparts = explode($_SERVER['REQUEST_URI']) // = '/path/to/somewhere/index.html'
$path = $uriparts[1] // = 'path'