Skip to main content
Participant
May 15, 2009
Answered

Trouble with Login Redirect [$_SESSION['PrevUrl']

I'm using the DW functionality to confirm that a user is logged in before allowing access to a page. Everything works except successfully redirecting to the previous URL. Here's the situation:

  1. User accesses a page with a url such as "addtocookbook.php?recipeid=6".
  2. Since the user is not logged in, they are redirected to"login.php".
  3. After successfully logging in, the user is redirected to "addtocookbook.php" without the "recipe=6".

My login page does attempt to direct the user to the previous url (if it exists). I'm not sure if there is a simple way to make the variable $_SESSION['PrevUrl'], used by DW to redirect,  store the entire url.

Any help is appreciated.

Elie Chocron

This topic is closed to new replies. Start a new post to keep the conversation going.
David_Powers
David_PowersCorrect answer
Inspiring
May 15, 2009

The problem lies with some obsolete code in the Restrict access to page server behavior. Fortunately, the fix is quite simple.

The affected section of code is as follows:

if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}

All that is necessary is to replace the three instances of $QUERY_STRING like this:

if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}

The redirect will then work correctly.

2 replies

David_Powers
David_PowersCorrect answer
Inspiring
May 15, 2009

The problem lies with some obsolete code in the Restrict access to page server behavior. Fortunately, the fix is quite simple.

The affected section of code is as follows:

if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}

All that is necessary is to replace the three instances of $QUERY_STRING like this:

if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}

The redirect will then work correctly.

Translate
Participant
May 18, 2009

Thanks! That did the trick.

Translate