• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[tutorial][php] get where you want, faster and easier!

hans henrik

Active Member
Joined
Jun 5, 2007
Messages
320
Reaction score
39
Location
Norway
This tutorial will teach you how to make "pma"=="http://127.0.0.1/phpmyadmin",
"lol=="127.0.0.1",admin=="127.0.0.1/admin_panel",
etc. it works on ALL major browsers (IE6+,FF*,Opera*,Safari*,Chrome*, even your tibia ip changer can benefit!)

(note to Mac/Linux/BSD: this tutorial is written with the assumption that the user is running Microsoft Windows*
but all 4 mentioned OS's have a similar hosts file,
and the method described here is possible on mac/linux/bsd/etc as well.)

1: find the hosts file
you need to find and edit the "hosts" file on your computer.
you can read on how to find it here:
Hosts (file) - Wikipedia, the free encyclopedia
usually, on XP/7, it is
32-bit:
C:\Windows\System32\drivers\etc\hosts
64-bit:
C:\Windows\SysWOW64\drivers\etc\hosts
alternatively, you can press Windows+R (windows referring to the "Win"/"Windows Button")
and in the box that pops up, write this exact string
Code:
cmd /c cd "%SystemRoot%" && dir hosts /s /b && pause
and a black window will appear and after a few seconds, show you where the hosts file is.

2: Edit the hosts file
Open the hosts file in notepad
Note that this requires "Administrator"/"Run as administrator"
add at the bottom of that file
127.0.0.1 lol
127.0.0.1 phpmyadmin
127.0.0.1 pma
127.0.0.1 sql
127.0.0.1 admin
(feel free to add/remove whatever you may or may not need from the list!,
I leave it up to you to understand the syntax of the hosts file ;))
Save and exit..
now you need to restart all your browsers.

3: Edit index.php
Now open your index.php
and at THE FIRST LINE
add this
Code:
<?php
function redir($n,$d='http://127.0.0.1/'){$s=$_SERVER['SERVER_NAME'];$x="Location: ";if(is_array($n))foreach($n as $n=>$d)if($n==$s)die(header($x.$d));if($n==$s)die(header($x.$d));}

redir(array(
'phpmyadmin'=>'http://127.0.0.1/phpmyadmin',
'pma'=>'http://127.0.0.1/phpmyadmin',
'sql'=>'http://127.0.0.1/SQLTEST',
'admin'=>'http://127.0.0.1/admin_panel.php',
'example'=>'http://example2.com/'
));
//can be used without array also.
//redir('srv','http://www.example.com');
//redir('gmail','http://www.gmail.com');
?>
(again feel free to add/remove whatever you may or may not need from the list)

save and exit.. now you are pretty much done! :D

try enter "pma" in your browser
(Google Chrome Note: Chrome will enter google search for "pma"/X,
and ask you once "did you mean http//pma/ ?" but it learns this after the first time!)
also note: "lol" even works in your ip-changer! etc

feedback is very welcome!

Questions/Answers:

Why?
I have written "localhost" and "127.0.0.1/phpmyadmin" and "127.0.0.1/SQLTEST" etc like a million times in my life...
(figure of speech, I have no idea how many times! just know its many...)
I just want an easier/faster way to do it, call me lazy if u wish :p


is there a developer-friendly version of redir the function?
yep. (nfo:i made both functions, now public domain :p)
Code:
<?php
function redirect($name,$destination='http://127.0.0.1/'){
$server_name=$_SERVER['SERVER_NAME'];
if(is_array($name))
{
foreach($name as $name=>$destination)
{
if($name==$server_name)die(header("Location: $destination"));
}
}
if($name==$server_name)die(header("Location: $destination"));
}
?>

how did I come to think of this?
I was checking XAMPP's default webpage code, and...
Code:
<?php
	if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
		$uri = 'https://';
	} else {
		$uri = 'http://';
	}
	$uri .= $_SERVER['HTTP_HOST'];
	header('Location: '.$uri.'/xampp/');
	exit;
?>
Something is wrong with the XAMPP installation :-(
made me think of doing this.
 
Last edited:
Back
Top