Jump to content

Auto Redirect in 3 seconds!


farnoise

Recommended Posts

Hi,

I have a logout.php page that kills the cookies and logs out the user and here is the code. What I have here it transfers the user to the website main page using simple HTML tag to as you can see INDEX.PHP so I just wonder if anybody can tell me how can I modify this code the instead of transferring them to INDESX.PHP just kills the cookie and after showing them the message "You successfully logged out" transfer them back to the page they were before, Kind of transfer to the referrer link

 

 

<meta http-equiv="refresh" content="4; URL=\index.php">
<?PHP
session_start();
session_destroy();
?>

<html>
<head>
<title>You are Logged out</title>


</head>
<body>
User Logged Out
</body>
</html>

Link to comment
Share on other sites

<?php

header( 'Location: http://www.yoursite.com/new_page.html' ) ;

?>

 

Just simply that, do not put any html before this or it may not work.

 

or

 

      <?php

      ob_start();

      echo "Test"; // Put you message here and delay here too

      header("Location: http://www.php.net");

      ob_flush();

      ?>

Link to comment
Share on other sites

Thanks for reply but there are 2 things!

1- what is NEW_PAGE.HTML I dont want to specify any page, I just want PHP to return the user to the page he was before

Example: if someone is in the Index3.php page and clicks log out ==> Log him out show the log out message and take him back to Index3.php

and

if someone is in the Index2.php page and clicks log out ==> Log him out show the log out message and take him back to Index2.php

 

2- If I sepcify header in my file I cant hsow them logout messag, It takes user directlyto the header page

 

 

Thanks

Link to comment
Share on other sites

1) new_page.html is the page you want to direct them to.  He meant for you to substitute the page you want there.

 

2) The user doesn't need to see a logout message.  I'm the user.  I clicked logout.  I don't need a message saying "You're logged out."  By redirecting the user back to the home page, which should have a login form on it, the user will receive confirmation that they are logged out automagically.

Link to comment
Share on other sites

when they logout send a variable with the logout equal to that page they are on.

//$my_location = Get .. Request... Post...  whatever your preferred method is here for getting that variable.

echo "You are logged out";

//destroy the cookies here

//Run a delay here...

header( $my_location ) ;

 

That should work, if header is not working right then you want try a buffer flush. What I was doing in the second example. That doesn't always work with all apache servers I forgot sorry... http://us3.php.net/manual/en/function.ob-start.php

 

I have a couple other non-header style scripts but have to find them. I'll post them when I do.

Link to comment
Share on other sites

when they logout send a variable with the logout equal to that page they are on.

//$my_location = Get .. Request... Post...  whatever your preferred method is here for getting that variable.

echo "You are logged out";

//destroy the cookies here

//Run a delay here...

header( $my_location ) ;

 

You have an error in your logic.

 

You have errors in your logic.

Link to comment
Share on other sites

1) new_page.html is the page you want to direct them to.  He meant for you to substitute the page you want there.

 

2) The user doesn't need to see a logout message.  I'm the user.  I clicked logout.  I don't need a message saying "You're logged out."  By redirecting the user back to the home page, which should have a login form on it, the user will receive confirmation that they are logged out automagically.

 

1- I understood that I have to substitude but as You can see I dont need to direct them to any page simply want to SEND THEM BACK TO THE REFFERER LINK!

 

2- I NEED to show the message!  :facepalm:

 

 

Link to comment
Share on other sites

1) $_SERVER['HTTP_REFERER'];

 

2) Do one of the following:

a) Append something to the url, such as $_SERVER['HTTP_REFERER'] . "?logout=true" and print a message based on that

b) Store the logout message in $_SESSION (of course after destroying whats already there) and print a message based on that

c) Use a meta refresh -- http://en.wikipedia.org/wiki/Meta_refresh

d) Use a javascript refresh -- http://www.tizag.com/javascriptT/javascriptredirect.php

 

- I NEED to show the message!

Unless you're under some sort of contract (or homework assignment), I'd disagree.  :)

Link to comment
Share on other sites

Ah I see.  I didn't know there was a Refresh header and you never mentioned it so I thought all of your references were to Location.

 

At any rate, causing a delay in the PHP script is pointless.

 

I forgot I could do that, it essentially same as a meta refresh(so same thing you told him to do since header() sends a raw HTTP  header. it is not a php refresh) and makes the code easier to understand. And sudo code is just that, referencing to location makes no sense whatsoever so if that what it came out as then yes the logic is wrong. I apologize if it came out that way.

 

 

However since you didn't point the errors out... I'll explain the one that matters to him:

/////////THis doesn't work//////
echo "Test"; // Put you message here and delay here too
      header("Location: http://www.php.net");

My logic is wrong here, because I need the refresh in the header to make the echo work before so this code below works....but the not the one above.

////////This will assuming you give $url an address as such http://mypage.net
echo "Hello!"; /// tell them your message here
header('Refresh: 3; url="'.$url.'"'); 

Link to comment
Share on other sites

echo "Hello!"; /// tell them your message here
header('Refresh: 3; url="'.$url.'"'); 

 

Unless output buffering with ob_start() has been...uh...started, that won't work.  The call to header() must come before any echo's (again only if output buffering is off).

 

I know you already mentioned ob_start() in this thread, I just don't want the OP to get confused.

Link to comment
Share on other sites

lol, oops yeah my bad there. I could have sworn I pointed that out (the ob_start I mean) there too. Thanks man.

That's what I get for only half paying attention.

 

Anyways an alternative method method that I was trying to explain that does actually work(if as pointed out certain settings are set) instead of me typing it backwards (damn the dyslexia...). This should work as is on most server settings, if not read about buffers ob_start etc.. on php.net Sorry for the confusion mates.

 


<?php
//  refresh / redirect to an external web page
//  ------------------------------------------
header( 'refresh: 10; url=http://www.php.net' );
echo 'You will be re-directed in 10 seconds...';
?>

<?php
//  refresh / re-direct without delay
//  ---------------------------------
header( 'location:http://php.net/' );
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.