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!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am not a PHP developer, but I have been given a site that we need to host, which is in PHP. I have copied all of the files to my server and uploaded the db to my MySQL server. Everything on the site runs perfect, except for my admin page. I cannot my page to redirect to the proper page. Here is the code... again I did not write this so I have limited knowledge on why things are the way they are:
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "home.php";
$MM_redirectLoginFailed = "index.php?login=failed";
$MM_redirecttoReferrer = false;
mysql_select_db($database_connection, $connection);
$LoginRS__query=sprintf("SELECT username, password FROM admin_users WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)) or die(mysql_error());
$LoginRS = mysql_query($LoginRS__query, $connection) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS) or die(mysql_error());
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
The part that is not working would be the very last IF statement. On the site that is currently active this page redirects to: http://www.mysite.com/admin/home.php
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]
I cannot my page to redirect to the proper page. Here is the code... again I did not write this so I have limited knowledge on why things are the way they are:
So what makes you think any of us are better equipped???
Anyways...If your having troubles redirecting to the wrong URL I suspect...that it's probably the variables being appended to header()...why not run some tests on those and find out why they are being set incorrectly?
I think that you are right, please figure out what the PrevURL is, because it is saying that $MM_redirectLoginSuccess equals your stored session's previous url. So when the 'if' statement is true it goes to the previous URL that was stored in the session.
This is what I would do, make a backup of the current php file, then change the header("location: ".$MM_redirectLoginSuccess); to
In the notes section of the manual on header() you'll find:
PHP Manual for header() wrote:
Note: HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:
<?php
/* Redirect to a different page in the current directory that was requested */
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;
?>
Note: Session ID is not passed with Location header even if session.use_trans_sid is enabled. It must by passed manually using SID constant.