Log in

View Full Version : Resolved url masking



TwitterRooms
01-10-2012, 08:04 PM
hi guys i have been trying for days i have made a simple site for a friend the problem im having is with the URL eg i start with /index.php (asks for login) after goes to /menu.php (make choice) /survey.php ect

how can i just make it domain.com or domain.com/index.php=????? or just domain.com/index.php

thanks all :confused:

djr33
01-10-2012, 10:41 PM
You can't, using the files you have at the moment. If you want one URL (or one URL with ?...) then you need to have one file.

You can use include() to use multiple files, and you can use conditional if statements to decide which page to include. So you don't need to literally put everything in one file, but you will need one central file that decides what to display.

Although it is possible to, for example, check whether data was submitted and display a different page because of that, using the ?... format will be much easier and more reliable. Look up how to use "GET" variables in PHP. The URL format is easy, just use index.php?var=value&var2=value2 and so on. Then to access them you will use the $_GET array, so that you can use $_GET['var'] which will have a value of "value".

TwitterRooms
01-11-2012, 08:44 AM
Thanks I'll have a go

What about .httacesses file can it be done with that?

djr33
01-11-2012, 09:06 AM
Well, that depends on what you mean. You still need to get the information into the PHP somehow.

You could use .htaccess with mod_rewrite to use 3 URLs but load only 1 file. But that's the opposite of what you said. I'm not really sure how mod_rewrite would help too much here. You could try to add some rules about the GET or POST data, but that's complicated and is probably best handled with PHP.

I'm still not sure why you want this. What is "masking"? Do you mean that you want to hide the URL? It will still work the same way, so nothing will be hidden-- it will just have a new name. Or did you just want to rename it? If that's all, we can help find a way to do that.

traq
01-11-2012, 03:17 PM
If you want to "hide" the URL - it seems that may be what you're asking - you should be aware that doing so creates many usability problems. It also ruins bookmarking, search engine indexing, and can create many technical difficulties to work around.

If you want to completely hide the URL, the best option is to use only one page and use AJAX to load the different content from the server when needed. (Although this still creates most of the problems I mentioned above. The URL is important! It should not be hidden, it should be used!)

djr33
01-11-2012, 11:13 PM
Just to add to what traq said, even if you do hide the URL, it won't be "secure", so if you're using this for security, it's better to use another approach. If you just don't want users to randomly find the page (or go back to it), that is possible, but it's not going to really be secure.

The other way to approach this would be to use a random "password" in the URL as part of a GET variable.
page.php?code=123456789
You could use sessions to generate this code and let it work only one time. If you really need a page to only load once, that's a good way to do it. Then if they don't have the right code, use a redirect to send them away from the page and exit; to stop more content from loading.

crobinson42
01-14-2012, 02:21 AM
have you checked out AJAX dynamic content loading into a <div> or using an iframe? Neither will be good for security but will accomplish a 'clean' look in the url..

TwitterRooms
01-14-2012, 01:02 PM
i solved this problem by puting

require_once('auth.php');
at the top of all files
then
auth.php was like this

<?php
//Start session
session_start();

//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
header("location: login-form.php");
exit();
}
?>

Thank you all for you help with this matter