Below is a code snippet from a login page. Function redirect() uses header('location: $URL') to redirect to a different page.
Could someone explain why the following code works:
<?php
session_start();
if ($submitted == 'TRUE')
{
session_register('username');
session_register('password');
session_register('db_name');
redirect('/phpMyAdmin/');
}
?>
...And this code does not:
<?php
if ($submitted == 'TRUE')
{
session_start();
session_register('username');
session_register('password');
session_register('db_name');
redirect('/phpMyAdmin/');
}
?>
With the second example, the page is redirected, but the session is not started...
I know that the browser cannot set a cookie once headers are sent, but I would think in this example that the session cookie would be set, but the page would not redirect... why is it backwards?
Could the second example work if output buffer functions or appending the PHP Sess ID to the URL were used?
~Mark