PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to make a login page which will redirect to another page once the login is successful. I am keeping things very basic for now with a hardcoded username and password. I really don't understand what the $_SERVER[] (lines 42 and 50) command is exactly (even after reviewing the php documentation and googling) and how I can get my page to link to another page.
Basically what I want to do is enter the correct username and password and link to a main menu-like page. I am not very familiar with php, but I have a feeling my problem is something to do with the $_SERVER command.
$_SERVER is a superglobal array. It simple gives you access to some information about the user and the server environment, things like; users IP, users user-agent (browser, OS, etc), the server's IP, the server's software it's running (this is a string composed of some of the different modules running).
In your case $_SERVER['PHP_SELF'] is being used. This is simply the location of the current page. So your login form posts to itself, then if you're logged in the server tries to forward you to "$_SERVER['PHP_SELF']".
Now, you said you're getting a blank page. You haven't escaped the variable inside the header() function so you're actually trying to forward to a page called "$_SERVER['PHP_SELF']", rather than the value of it. If you want to redirect to the login page again then just escape the $_SERVER inside header():
header("Location: ".$_SERVER['PHP_SELF']);
When using header() you must make sure absolutely NO output is sent to the browser, this includes whitespace (a space before the openning <?php tag.
If you don't have error reporting on and you're outputting something before header() then you'll get a blank page.
What is the URL in your address bar? The same as the one with the form in? If so then header() isn't being called (assuming you're not using $_SESSION['PHP_SELF'] like you said you changed).
Yeah, absolutely everything does. You don't need to output anything if you're redirecting the user because they'll never get to see it. If you're thinking of making a redirect page for the user ("You are being redirected, if you are not redirected in 5 seconds, click here..." kind of thing) then Google 'meta refresh'. - although header() is the way to go.