/    Sign up×
Community /Pin to ProfileBookmark

Conditional URL directing

Conditional URL directing
————————————————————————

I’m a total, complete newbie at this, so I need a lot of help!

I’m looking for code that does something along the lines of the following:

User is asked to enter a code.

If code=A, then they get directed to URL1

If code=B, then they get directed to URL2

If code is left blank or user enters nothing — or anything other than A or B, then they get directed to URL3.

Thanks in advance!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@aaronbdavisJul 02.2006 — First you will need either a form, or create a link for each item.

Choose either the GET or POST method (I would suggest GET).

Assuming you choose GET, you could handle it as follows (although there are other ways to do it):[code=php]$code = $_GET['code'];
switch ($code)
{
case 'A':
$url = 'http://somedomain.com";
break;
case 'B':
$url = 'http://anotherdomain.com";
break;
default:
$url = "http://athirddomain.com";
break;
}
header('Location: ' . $url);[/code]

the $url variable can be any valid URL; it does not have to be for another site, if you just want to direct users to another page on your site.

HTH,

Aaron
Copy linkTweet thisAlerts:
@tabzterJul 02.2006 — This is better suited to..............Javascript !

<script type="text/javascript">

var code=prompt("Enter Code","Enter Code Here");

switch (code.toUpperCase()) {

case 'A' : window.location.href="URL1.html";

case 'A' : window.location.href="URL2.html";

default : window.location.href="URL3.html";

}

</script>

but if you need PHP then you can only use forms. Holla at me if you NEED php
Copy linkTweet thisAlerts:
@shaaaauthorJul 05.2006 — Thanks tabzter. Sorry for the delayed response. Was away for the July 4th weekend.

I was able to make your script work after adding break; at the end of Lines 4 and 5. It does what I want it to.

Since you offered, how would I do it with PHP? Thanks in advance!
Copy linkTweet thisAlerts:
@SheldonJul 05.2006 — To do it in PHP, just use what arron b davis said.
×

Success!

Help @shaaa spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...