Jump to content

Recommended Posts

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

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

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

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

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  :D

Link to comment
https://forums.phpfreaks.com/topic/142856-page-redirect/#findComment-748918
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.