problem with redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Beebosoft
Forum Newbie
Posts: 12
Joined: Mon Jun 25, 2007 9:18 am

problem with redirect

Post by Beebosoft »

JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a page that is checking info to see if this is the appropriate page for the user to be on.  if it is it looks up the registered persons details and books them onto a course.  if they are not it should redirect to a page for them to register first.  

There are two checks above the html code which deal with the redirects. The first check is to see if the user has logged on which has a header redirect in it.  the second is to see if they are all registered.  This too has a header redirect on which seems to be working.  

 I have split the code into 2 sections.  the top deals with the checking etc and appears before the usual html stuff ( I want this page to look like the rest on the site I need the html stuff there.)  the code is as follows

Code: Select all

<?php
session_start();
	if (!isset($_SESSION['valid_user'])){
		header("Location: login.php");
	}
	else
	{
$courseid= $_POST['courseid'];
$email = $_POST['requiredEmail'];
	//get connection to database
	 $linkID = @mysql_connect("localhost", "root", "");
	mysql_select_db("ivanhoe", $linkID);
	 //set error reporting to display and to it's highest level in case 
	 //it's not and you're missing vital notices and/or warnings: 
	ini_set('display_errors', 1); 
	error_reporting(E_ALL); 
	$sql ="SELECT * FROM clients WHERE email LIKE '$email'";
	$resultID = mysql_query($sql, $linkID)or die(mysql_error());
		if(mysql_num_rows($resultID) < 1) 
		{
		$goto ="notregistered.php?id=$courseid";
		header( "Location: $goto" );
		}
	}
		?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
If they have registered etc the there is code further down the page do do.

My problem is that although there is a redirect if the user is not registered and it does redirect, it still appears to add the details to a booking table etc. which is what the code further down does.

Have i made a fundemental series or errors in my thinking here. how can I stop the code further down the page happening if the user needs to be redirected?

Any help would be appreciated


JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

Code: Select all

header( "Location: $goto" ); 
exit();
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Make sure $goto is a full URL, http:// and all.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

And every now and again try searching. I just answered this exact same question yesterday.
Post Reply