denoteone Posted January 28, 2009 Share Posted January 28, 2009 If I have a form on my html page that on submit calls the php at the top of the page. The php then check a few things about the posted data sets some sessions and then if all is ok it should go to a predetermined page. How do I send the user to that page. I can't header("Location: index.php"); because data has been sent to the browser already. Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/ Share on other sites More sharing options...
gevans Posted January 28, 2009 Share Posted January 28, 2009 What data have you already sent to the browser? can you show your script? Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748883 Share on other sites More sharing options...
Maq Posted January 28, 2009 Share Posted January 28, 2009 Why can't you use the JS redirect? <br /> <!--<br /> window.location = "index.php"<br /> //--><br /> Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748885 Share on other sites More sharing options...
.josh Posted January 28, 2009 Share Posted January 28, 2009 read the headers already sent sticky in this forum. You can use ob_start() as a bandaid or you could code properly and avoid having to bandaid to begin with. Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748886 Share on other sites More sharing options...
gevans Posted January 28, 2009 Share Posted January 28, 2009 @Maq People could have javascript disabled... then you get a confused user Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748889 Share on other sites More sharing options...
denoteone Posted January 28, 2009 Author Share Posted January 28, 2009 here is my code <?php error_reporting(E_ALL); ini_set('display_errors', 1); include 'connect.php'; if(isset($_COOKIE['ID_my_site'])) { $usersemail = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $password = md5($pass); $check = mysql_query("SELECT * FROM users WHERE email = '$usersemail'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($password != $info['passwords']) { //header("Location: index.php"); die($password); } else { if (isset($_POST['send'])) { session_start(); $_SESSION['price_project_area'] = $_POST['project_area']; //I will also check to make sure everything is completed //this is where I need to redirect to the next page } else { ?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>Get a Price Quote</title> <link rel="stylesheet" href="style/sheet1.css" type="text/css" /> </head> <body> //content <form action="$PHP_SELF" method="post"> </form> </body> </html> <? } } } } else { header("Location: index.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748908 Share on other sites More sharing options...
contra10 Posted January 28, 2009 Share Posted January 28, 2009 do all the checking in the php script and when all is finished place at the bottom of your script inside if brackets...im assuming **if (isset($_POST['send'])){ }** // Create the URL string $url = "http://localhost/..."; // Finall Echo the meta tag echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">'); that should redirect after you have completed all the checking u wish...this is a backup to using header...not really used toomuch since its html in php but it works Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748911 Share on other sites More sharing options...
gevans Posted January 28, 2009 Share Posted January 28, 2009 That'll do it for you; <?php error_reporting(E_ALL); ini_set('display_errors', 1); include 'connect.php'; if(!isset($_COOKIE['ID_my_site'])) { header("Location: index.php"); } else { $usersemail = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $password = md5($pass); $check = mysql_query("SELECT * FROM users WHERE email = '$usersemail'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($password != $info['passwords']) { //header("Location: index.php"); die($password); } else { if (isset($_POST['send'])) { session_start(); $_SESSION['price_project_area'] = $_POST['project_area']; //I will also check to make sure everything is completed //this is where I need to redirect to the next page } else { ?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>Get a Price Quote</title> <link rel="stylesheet" href="style/sheet1.css" type="text/css" /> </head> <body> //content <form action="$PHP_SELF" method="post"> </form> </body> </html> <?php } } } } ?> Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748913 Share on other sites More sharing options...
TheLoveableMonty Posted January 28, 2009 Share Posted January 28, 2009 I think I get what's trying to be accomplished here. Without seeing the code, it's hard to know. Answering the JavaScript redirect query, why not use a Meta tag? <meta http-equiv="refresh" content="10,URL=http://www.yourwebsitehere.com"> In the example shown, the page would redirect in ten seconds to the URL specified. If there are multiple locations you can go, have the URL saved as a variable and print the variable in the meta tag. Example: if ($uname = "Paul") { $url = "http://www.paul.com"; } print "<meta http-equiv=\"refresh\" content=\"10,URL=$url\">"; That's how I redirect pages in PHP. EDIT: Three people posted while I was typing. Damn pizza break Link to comment https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.