Domanda

I want to use an idea that I have seen on another website where I enter a "keyword", press Enter, and it then takes the client to a specific page or website.

I have seen something like this on http://qldgov.remserv.com.au, On the right side there is a field called "My Employer", type in "health" for example and you will be provided with relevant content.

Essentially I have client branded mini sites where we want to assign a "keyword" for each client brand so all of their employees will be able to go to their site entering this one keyword without all of them having individual logins. I want to be able to link to a URL that I can define in some manner.

I have looked at the source code of the site mentioned above and see they are using a form but I am not sure how they have assigned the keywords or if its even possible to do this without a database or anything like that. Trying to keep it as simple as possible as I am not a PHP/Java expert by any means.

Any help would be appreciated, even if its not code but an idea of the direction I need to go in to make this work. Thanks in advance!! :-)

È stato utile?

Soluzione

The easiest way in my eyes would be to define an array that contains all of the keywords and respective urls client side (in JS). For example:

​var array = { 'health' : '/health.php', 'sport' : '/swimming.php' };

You would then get the user input on onSubmit and if it exists modify the window.location appropriately.

if ( array[user_input] !== undefined ) {
     window.location = array[user_input];
}
else {
     alert ( 'not found' );
}

If the user supplied health they will be redirected to /health.php, if they supply sport they will be redirected to /swimming.php (JSFiddle). Alternatively you can use server-side (PHP, JAVA) to handle the request but this may not be worth the effort.

Goodluck.

Altri suggerimenti

By using php (rather than javascript), you're not relying on javascript + making it seo friendly.

Firstly you're going to need either some sort of database or a list of keywords/urls

$keywords = array('keyword1' => 'path/to/load.php', 'another keyword' => 'another/path');

Then you'll need a basic form

<form action="loadkeyword.php">
  <input name="query">
  <button type="submit">Go</button>
</form>

Then in loadkeyword.php

$keywords = array('keyword1' => 'path/to/load.php', 'another keyword' => 'another/path');
$query = $_GET['query'];
if (isset($keywords[$query])) {
   $url = $keywords[$query];
   header("HTTP/1.0 301 Moved Permanently");
   header('location: '.$url);
   exit;
} else {
   header("HTTP/1.1 404 Not Found");
   die('unable to locate keyword');
}

If you have a large list of keywords, I would suggest using a database instead of an array to keep track of your keywords.

The site you link to is doing it server-side, either via a keyword-list that matches content or a search function (I suspect the latter).

There are a few different ways you could achieve your goal, all of them to do with matching keywords to content and then redirecting, either with an array, a list, or a database - the principle will be the same.

However, I would respectfully suggest this may not be the best solution anyway. My reasoning is that (based upon the example you give) you're effectively making your users guess which keyword matches which minisite (even if you have many keywords for each site). Why not just have some kind of menu to choose from (i.e. a selector with a list of minisites)?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top