As some might have already seen in previous journal posts, I'm working on a website for work.
As I have complete freedom over the design, I chose to make it in PHP to learn a new technology. It's going pretty well (special thanks to Penguinboy for pushing me in the right direction with CSS), but I'm facing a new obstacle right now. I don't think it's directly related to PHP though.
I need to make a conditional redirect, but I find I don't even know how to make a "normal" redirect.
The intended design is:
a.php has a textbox and a submit button. Enter the right string and you are redirected to b.php?event=stringentered . With a wrong string you just come back to the same prompt, maybe with an error message.
b.php only needs to send you back to a.php when no string is passed to it.
Right now, I only have one php page that does both, and it works, but I think it's a mess and I wonder if it would be "cleaner" with two pages instead.
Does anyone have an idea?
[PS. I could really use some text formatting features here such as bold, italics, etc. like in forum posts...]
It might or might not help you out on what you need, but at least it's free to use. Here is this little PHP redirect script that I found called "GoTo".
PHP GoTo will redirect a user to an URL that they select from a form. The allowed protocols are HTTP, HTTPS, and FTP. If the protocol is not specified with the form data, it defaults to HTTP.
You can download the script directly from here: http://www.lampscripts.net/node/3/release
Use an MVC framework or DIE.
Also, Tito, please stop trying to respond to things you know nothing about.
I have already gotten paid over $22,000 from the past 3 years part time doing a few commercial websites for small business. I know it's not a lot, but it's a start. On top of that, my PayPal account gets about $400 to $600 a week from my various web stores that I created and own. The amounts will just be getting bigger as time goes on. And in April, I will be joining a web developer team as freelance consultant to work on an online state government project dealing with law enforcement. This job has a completion budget set at 4 million dollars! For this consultant job, I will be getting paid $36 an hour for the space of 4 months. I might not have the fancy I.T. degrees or be completely fluent with all the web developing technologies out there, but I do know enough for what I really need to know to get the job done. And you know what is the best part about all this from me? I am my own boss, I do not work for no body else, period. So, you still want to tell me that I don't know anything? There's a little saying that I always liked a lot: "Money talks, bullshit walks".
exit();
Redirecting isn't beautiful though, you might want to re-think your desgin.
You don't have to use MVC. MVC is very popular and for good reason, but there are other ways to code. You'll do just as well without it if you're making a really small website.
Going back to the original topic, I'm not sure if potatis' solution would work, as what I need is a conditional redirect, and as far as I know, header statements cannot have any other statements (including if) before them.
And regarding Penguinboy's solution, I don't mind using a new technology but for now I'd prefer a simpler solution (especially because I only need this conditional redirect right now, maybe I'll use that in future projects)
So how do you think I should use die()?
That's a common myth. You can for example write
if(rand(0, 1)) {
header("Location: a.php");
exit();
}
You can't however, make changes to the header after you have output data (for example using echo or imagepng), because then it'll already have been sent to the client.
"So how do you think I should use die()?"
I don't think he's talking about the language construct (which by the way is equivalent to exit)...
Also I'm starting to think he didn't say die(); but (grabbing sword) DIE!!!!!!!!!!
There is a plan to include a new module in the future, to track employees schedules, but the database part of it was the first thing I thought of.
I can offer you to help with the database design for TWHL4 if you need a hand. It seems to be something I enjoy.
Do you know where could I learn more about a MVC framework? I've never used one.
If you have access to a copy of visual studio 2008 you should grab ASP.NET MVC and use some of their resources - even if you don't have a ASP.NET hosting service (just use it locally to learn MVC), ASP MVC is by far the best and easiest MVC framework to use, and it's a great one to start on because there are so many resources for it. C# is easy as cake, you can pick it up quite quickly. Also recommended is the book on ASP MVC by Steve Sanderson (easy to find in ebook form) to help you learn the basics.
If you don't wanna go that way you may have a bit more trouble figuring it out but there are lots of resources on the topic floating around the internet, but ASP MVC is by far the best way to get a concept of MVC. Once you get the basics down, you can move on and choose a framework for PHP. My favourite is Kohana (linked above), but you could also look at CodeIgniter, CakePHP, and others. The Wikipedia article might help, as well as various tutorials and documentation on the websites of the MVC frameworks themselves.
If you want to you can grab me on IRC and I can give you some pointers to start you off on MVC.
if (isrequestvalid())
{
header("location: a.php");
exit();
}
It's just what I needed.