Code specific redirect? E.g. Enter 123, redirected to /123.
Moderator: General Moderators
Code specific redirect? E.g. Enter 123, redirected to /123.
I'm setting up a website and part of that website concerns clients and their respective projects.
What I want do is make a code specific redirection. I'll explain in more detail: I want to make a page where the client has to enter a code such as 123456. I then want that code to be run through a script where that code is recognised, when the code is recognised, I want the client get redirected to a pre-defined directory of my choice such as /123456 or a page 123456.htm.
To put it simply: enter the code 123456, get redirected to /123456
I'm a HTML developer who's moving onto PHP but just needs a little help, correct me if I used the wrong terms above and please do ask further if you do not fully understand; I'm not good at explaining things.
Thank you. Steven.
What I want do is make a code specific redirection. I'll explain in more detail: I want to make a page where the client has to enter a code such as 123456. I then want that code to be run through a script where that code is recognised, when the code is recognised, I want the client get redirected to a pre-defined directory of my choice such as /123456 or a page 123456.htm.
To put it simply: enter the code 123456, get redirected to /123456
I'm a HTML developer who's moving onto PHP but just needs a little help, correct me if I used the wrong terms above and please do ask further if you do not fully understand; I'm not good at explaining things.
Thank you. Steven.
Re: Code specific redirect? E.g. Enter 123, redirected to /123.
Hey, there! Don't worry, that's not too difficult.
Make a form that posts back using method="get".
Read the variable, and if it has been posted add an HTTP redirect to example.com/(your variable)
If you need more specifics, let me know.
Make a form that posts back using method="get".
Read the variable, and if it has been posted add an HTTP redirect to example.com/(your variable)
If you need more specifics, let me know.
Re: Code specific redirect? E.g. Enter 123, redirected to /123.
I'm very new to PHP only knowing a few commands like echo and that, so specifics would be a appreciated. Thank you.omniuni wrote:Hey, there! Don't worry, that's not too difficult.
Make a form that posts back using method="get".
Read the variable, and if it has been posted add an HTTP redirect to example.com/(your variable)
If you need more specifics, let me know.
Re: Code specific redirect? E.g. Enter 123, redirected to /123.
Don't worry, you don't need much more than an echo.
Go ahead and put that into a page, (a blank page will do), and you should see how it works. It lets you capture what the user enters into the form, and then write out code using that. There are several ways to redirect a user once you have the data, one uses meta data, for another check out http://us3.php.net/manual/en/function.header.php
Let me know if you need more specifics, but at least see if you can understand how this code works first.
Code: Select all
<?php
if(isset($_GET['directme'])){
$goToHere = $_GET['directme'];
echo "HTML for redirect to $goToHere";
}
?>
<form method="get">
<input name="directme">
<input type="submit">
</form>Let me know if you need more specifics, but at least see if you can understand how this code works first.
Re: Code specific redirect? E.g. Enter 123, redirected to /123.
Ah thank you very much, I changed the code a little after reading that link you gave me to:
Which works fine, but I would like to include an else statement so the user gets redirected to the same page again and is told that their ID wasn't found, would be be something like this:
Which doesn't work, so what I am missing? I really appreciate all of your help, thank you.
Code: Select all
<?php
if(isset($_GET['id'])){
$url = $_GET['id'];
header("Location: $url");
}
?>Code: Select all
<?php
if(isset($_GET['id'])){
$url = $_GET['id'];
header("Location: $url");
}
else {
header("Location: .");
}
?>Re: Code specific redirect? E.g. Enter 123, redirected to /123.
Oh and if you want to see it in action, you can here:
http://clearboth.co.uk/clients/
And enter the ID: 2009260701
Thanks for your help. Steven.
http://clearboth.co.uk/clients/
And enter the ID: 2009260701
Thanks for your help. Steven.
Re: Code specific redirect? E.g. Enter 123, redirected to /123.
Code: Select all
<?php
if(isset($_GET['id']) && is_dir($_GET['id'])){
$url = $_GET['id'];
header("Location: $url");
}
?>Oh, also, I would recommend adding a "submit" or "go" button... just because some people don't think to hit "enter".
Also, good job! Forums like these are here to help, but so many people come here just expecting to be told the answer. It's good to see someone who's willing to at least take a few minutes to think on their own. As usual, let me know if you have any more questions.
Re: Code specific redirect? E.g. Enter 123, redirected to /123.
The code I post a few days back is what I'm using now and it's good, simple and does what I want it to do. Thanks for linking me to those articles, good to add on bits of code and do good old trial and error to get things working.omniuni wrote:How's that work for you?Code: Select all
<?php if(isset($_GET['id']) && is_dir($_GET['id'])){ $url = $_GET['id']; header("Location: $url"); } ?>
Oh, also, I would recommend adding a "submit" or "go" button... just because some people don't think to hit "enter".
Also, good job! Forums like these are here to help, but so many people come here just expecting to be told the answer. It's good to see someone who's willing to at least take a few minutes to think on their own. As usual, let me know if you have any more questions.
Steven.