Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Login Redirect..?

extract redirect login

  • Please log in to reply
2 replies to this topic

#1 aakinn

aakinn

    CC Newcomer

  • Just Joined
  • PipPip
  • 17 posts

Posted 30 December 2010 - 04:52 AM

Hi all,

Im working on a login script which pretty much does what it says on the tin but having a slight problem when it comes to logging out.

I have this bit of code on all my pages to determine if there is a session or not, what to display and also grabbing the page URL so then I can use it to redirect the user back once logged out.

For arguements sake lets say we are on page "about.php"

about.php
<?php
function curPageURL() {
$pageURL = 'http';
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$thisURL= curPageURL();



include ('includes/openDB.php');
if ( isset($_SESSION['username']) ){
?>
<div id="loginbox">
<h2>Welcome <?php echo $_SESSION['username'];?> </h2><br />

<form action ="logout.php" enctype="x-www-form-encoded" method="post">
<input name="url" value="<?php echo $thisURL;?>" type="hidden"/>
<input type="submit" name="Submit" value="Logout"/>
</form>

<br />
</div>
<?
}
else{
?>
<div id="loginbox">
<form method="post" action="LoginDBase.php">
<table border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td><b>Username</b></td>
<td><input name="myusername" type="text" onblur="validateUsername(this.value)" id="myusername" size="10"/></td>
<td><b>Password</b></td>
<td><input name="mypassword" type="password" onblur="validatePassword(this.value)" id="mypassword" size="10"/></td>
<td><input type="submit" name="Submit" value="Login" /></td>
</tr>
<tr>
<td> </td>
<td id="uMess" colspan="2"></td>
<td id="pMess" colspan="2"></td>
</tr>

</table>
</form>
Forgot your details? <a href="forgot.php"> Click here</a><br />
Not a user <a href="register.php"> Register here</a>
</div>

<?php
}
?>


I have a $thisURL variable so when logout is clicked they will be redirected to the same page which they logged out from so I pass this value on.

Now on my logout page I have this

logout.php
//clean up magic quotes
if (get_magic_quotes_gpc()) {
$_POST = stripslashes_array($_POST);
}
// copy POST input to scalars
extract($_POST);

include ('includes/openDB.php');
if ( isset($_SESSION['username']) ){

//Unset the variables stored in session
unset($_SESSION['username']);

echo $url;
?>
<h2 class="title"></h2>
<div class="entry">
You have been logged out.
<p align="center"><a href="<?php $url?>">Click here to return back</a></p>
</div>
<br />



Im extracting the post which is the url variable. When I echo the value of $url it comes up with "about.php" which is correct so I have included it so that the user can click and return back to that page but when it is clicked it goes to logout.php.

Hope I have made it clear what my problem as it does seem quite perplexed.

Any ideas as to why it redirects to logout and not about?
  • 0

#2 plb

plb

    CC Newcomer

  • Member
  • PipPip
  • 19 posts

Posted 30 December 2010 - 05:33 AM

<?php $url?>

Replace this with: <?php echo $url; ?>
  • 0

#3 aakinn

aakinn

    CC Newcomer

  • Just Joined
  • PipPip
  • 17 posts

Posted 30 December 2010 - 05:37 AM

Jesus!! That was abit school boy!

Cheers fella
  • 0





Also tagged with one or more of these keywords: extract, redirect, login

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download