6 Replies - 1418 Views - Last Post: 23 May 2011 - 09:03 PM Rate Topic: -----

#1 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

On correct authentication, go to another page

Posted 23 May 2011 - 07:57 PM

I'm not exactly sure how to do this. I tried just throwing in an include statement, but that fails miserably.

Here's what I want to do:
A use puts in his login information, and if it's correct as stored in the database, it brings up the main page. I just don't know how to do this.

Here's what I tried:
if(isset($_POST['email']))// if the form has been submitted $POST['user'] will have a value-> even if that value is blank
{
	$email = sanitizeString($_POST['email']);// so if it's been submitted, set $email to the sanitized version of whatever was in the email field
	$pass = sanitizeString($_POST['password']);// if it's been submitted, set $pass to the sanitized version of whatever was in the password field
	
	// email and password validation
	if($email == "" || $pass == "")// if the email field or the password field were left blank...
	{
		$lerror = "Not all fields were entered<br />";
	}
	else// if neither were left blank...
	{
		$token = md5("$salt1$pass$salt2");
		$query = "SELECT email,password FROM members WHERE email='$email' AND password='$token'";// a query to get a row with the submitted email and password

		if(mysql_num_rows(queryMysql($query)) == 0)// if the query doesn't return any results (0 rows), then the email/password were incorrect
		{
			$lerror = "Username/Password invalid<br />";
		}
		else// if the query returned a result
		{
			// set the session variables to the submitted username and password values. These will be accessible to all programs in the project
			$_SESSION['email'] = $email;
			$_SESSION['pass'] = $pass;
			include_once("main.html");
			//die("You are now logged in. Please
					//<a href='znmembers.php'?view='$user'>click here</a>.");
		}
	}
}



And here's the form that's submitting from my HTML page:
<form method='post' action='testApple.php' class="login">
				<div>
					<span class="el">Email</span>
					<input class="box1" type="text" name="email" id="email"/>
				</div>
				<div>
					<span class="pl">Password</span>
					<input class="box2" type="password" name="password" id="password"/><span class="button"><input type="image" src="load.ico" name="image" width="24" height="24"></span>
				</div>
				</form>



So the form is on appleTest.php. If it's correct authentication, I want main.html to open up. If either email or password is incorrect, I want to stay on appleTest.php and print and error message (this part is working correctly).

Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: On correct authentication, go to another page

#2 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: On correct authentication, go to another page

Posted 23 May 2011 - 08:36 PM

In your code block, where correct authentication is ensured, instead of including main.html file, use header function to redirect to that page.

else// if the query returned a result
{
	// set the session variables to the submitted username and password values. These will be accessible to all programs in the project
	$_SESSION['email'] = $email;
	$_SESSION['pass'] = $pass;
	header("Location:main.html");
}



Was This Post Helpful? 0
  • +
  • -

#3 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: On correct authentication, go to another page

Posted 23 May 2011 - 08:49 PM

I add that and I'm getting this error message:

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\index_layout.php:9) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\appleLogin.php on line 32

I'm not exactly sure what this means. It doesn't redirect to main.html at all, this error message is just shown at the top of testApple.php

This post has been edited by eZACKe: 23 May 2011 - 08:55 PM

Was This Post Helpful? 0
  • +
  • -

#4 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: On correct authentication, go to another page

Posted 23 May 2011 - 08:55 PM

The error means you have already send some output data to the browser. You can't send header after you have outputted something. Either you have to use output buffering or other ways to redirect like javascript redirecting.

This post has been edited by atik97: 23 May 2011 - 09:01 PM

Was This Post Helpful? 0
  • +
  • -

#5 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: On correct authentication, go to another page

Posted 23 May 2011 - 08:58 PM

So is there any different way of doing this then? Or perhaps a way of getting around it? I have error messages showing if the email/password is incorrect, and that's always going to be before this.
Was This Post Helpful? 0
  • +
  • -

#6 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: On correct authentication, go to another page

Posted 23 May 2011 - 08:59 PM

You could use javascript redirect in this way -

else// if the query returned a result
{
	// set the session variables to the submitted username and password values. These will be accessible to all programs in the project
	$_SESSION['email'] = $email;
	$_SESSION['pass'] = $pass;
	echo '<meta http-equiv="refresh" content="0;url=main.html">';
}


Was This Post Helpful? 1
  • +
  • -

#7 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: On correct authentication, go to another page

Posted 23 May 2011 - 09:03 PM

Thank you. Exactly what I needed.

Thank goodness for Javascript. Makes things so much simpler :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1