Hi all
Can anyone please help me. I have the code below that provides text saying "You've been successfully logged in" but i would like this to redirect me to another secure page
Can someone please help me with the redirect code for my script.
Thank you
Code:<?php session_start(); if (!empty($_POST[username])) { require_once("connect.php"); $query = mysql_query("SELECT * FROM members WHERE username = '$_POST[username]' AND password = '$_POST[password]'") or die ("Error - Couldn't login user."); $row = mysql_fetch_array($query) or die ("Error - Couldn't login user."); if (!empty($row[username])) { $_SESSION[username] = $row[username]; echo "Welcome $_POST[username]! You've been successfully logged in."; exit(); } else // { echo "Error - Couldn't login user.<br /><br /> Please try again."; exit(); } } ?>![]()
Last edited by Roger; 09-10-2010 at 09:05 AM.
Just change the red code to match where you want to point them, and how long you would like to have the message displayed and that should do itCode:if (!empty($_POST[username])) { require_once("connect.php"); $query = mysql_query("SELECT * FROM members WHERE username = '$_POST[username]' AND password = '$_POST[password]'") or die ("Error - Couldn't login user."); $row = mysql_fetch_array($query) or die ("Error - Couldn't login user."); if (!empty($row[username])) { $_SESSION[username] = $row[username]; echo "Welcome $_POST[username]! You've been successfully logged in."; sleep(5); header("Location:filename.php"); exit(); } else // { echo "Error - Couldn't login user.<br /><br /> Please try again."; exit(); } } ?>![]()
Again,,upi are a star
Thank you very much for helping me out with my project.![]()
That is horribly inefficient, change the red code to this:
"5" being seconds to wait to redirect.Code:echo '<meta http-equiv="refresh" content="5;url=http://site.com/index.php">';
Be sure to read the updated FAQ || Health is achieved through 10,000 different steps.
A textual description can be only part of your question, be sure to provide sample results, errors and your platform in the appropriate forums while asking.
Personally, I take full advantage of $_SESSION and I would do something like:
for outputting any messages for the end user, or maybe switch to using AJAX if you want to get more technical? printing messages on a plain screen and then doing a redirect is very old-fashioned.Code:<?php
session_start();
if(is_array($_SESSION['msg'])){
foreach($_SESSION['msg'] as $msg){
print("<div class=\"msg\">{$msg}</div>");
}
}
unset($_SESSION['msg']);
session_write_close();
?>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks