Question

I'm helping out a friend with her web page and I can't seem to make sense of the routing. So this webpage was written years ago in php.

Essentially, there is stuff like this:

<li><a href="<? echo $_SERVER["PHP_SELF"]; ?>?goto=start">Startseite</a></li>
<li><a href="<? echo $_SERVER["PHP_SELF"]; ?>?goto=objekte">Objekte</a></li>
<li><a href="<? echo $_SERVER["PHP_SELF"]; ?>?goto=nachfrage">Wir suchen</a></li>
<li><a href="<? echo $_SERVER["PHP_SELF"]; ?>?goto=angebot">Sie bieten an</a></li>
<li><a href="<? echo $_SERVER["PHP_SELF"]; ?>?goto=kontakt">Kontakt</a></li

Which works with a switch statement later on in the php page:

 <?
switch ($goto) {
    case "start":
        include("./startseite.inc.php");
    break;
    case "jobs":
        include("./jobs.inc.php");
    break;
    ....
    default:
        include("./startseite.inc.php");
    break;
?>

Now, when I run this locally, clicking on the links nothing gets reloaded, which makes me believe that it is something with the routing rules. I am no php programmer so I don't know if this is a valid technique.

Could someone explain to me / point me into the right direction of how the goto of the url: www.site.com/index.php?goto=something, gets resolved to the $goto var in the php code

P.s. On the first visit to the page i.e. index.php, the startseite.inc.php does get rendered fyi

Sorry if this is confusing, but the whole site is written in a very unstructured way.

Thanks, Marc

Was it helpful?

Solution

By adding ?goto=xyz to a URL, you are adding the goto parameter (with the value xyz) to the HTTP GET request. PHP is capable of understanding these parameters. The only thing you have to do in order to access it's value is to read the corresponding value of PHP's built-in $_GET array like so:

$goto = $_GET['goto'];

PHP documentation on the $_GET array: Reserved variables: GET

Let me know if you need further explanation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top