Hello to all, first I am really sorry if i posted this thread in wrong section or something like that... :)
So i wanted to get some help from other people who uses PHP language. I want to ask for the best and secure way to do this. All kind websites uses the` http://webname?test=home,'rules','terms'` and so on. So how can i do the same thing a secured way and with more comfortable way than i know.
I know a way like this:

        if($_GET['test']=='rules')
        {
            do something...
        } else if($_GET['test']=='terms')
        {
            do something...
        }

And soo on.
    So how can i do like by ?test=... to do something without goving to another files like `http://webname/index.php' or http://webname/rules.php`... :)?

karolismf, you are wanting to URL rewrite (aka MOD_REWRITE), this is done via .htaccess file.

So for example you could turn this url:

www.somewebsite.com/index.php?s1=43&s4=44

Into something like:

www.somewebsite.com/43/44

hmm, so if i want to rewrite the include file like rules.php into ?=rules, i need to use MOD_REWRITE in htaccess? :) But that's something that only rewrites i need if ?a=rules in web is set to include a html file. and the include link can't be rules.php but need to be ?a=rules :)

Well if you want to execute an action you will always have to load a new file or reload the current file. The only exception is if you use AJAX to dynamically load a file (you know, like for example the search completion that Google uses, that's AJAX).

So, if you for example have a file called index.php, which contains a login form, and you want the user to stay on index.php even after he has logged in, you have several ways of achieving that. The first is to redirect the user as soon as he submits the form. For example you could redirect him to login.php, set a $_SESSION variable there that says he has been logged in, and then redirect him back to index.php, which then recognizes the $_SESSION variable and displays data that requires the user to be logged in.

Another way is to redirect the user to index.php?login=true, for example. Index.php then checks if $_GET['login'] has been set, and if it has, it checks the login. If the login then is correct, some new data is loaded, and if it is not, a login error is loaded. These are all examples, of course, just to show you *some* possibilities to achieve what I think you want to achieve :).

Yeah, that was a good example. But in my case it would be menu. In the menu the link is ?a=rules, when i press the link my web address is http://address.net/?a=rules. Then i use if($_GET['rules']=='rules'){include("rules.php");}. I just want a better way than write all the menu and the list with if(rules..) if(home...) if(terms..). So the code would be a bit better and more comfortable. :)

What about using a switch? Example:

<?php
switch($_GET['mode'])
{
    default:
    case 'index':
        include 'includes/index.php';
        break;

    case 'login':
        include 'includes/login.php';
        break;

    // Etc...
}
?>

Yes, thanks minitauros. I am doing the same idea as you suggest. Thanks for help. :)

You're welcome :). Glad you found a solution!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.