10 Replies - 634 Views - Last Post: 02 October 2009 - 09:40 AM Rate Topic: -----

#1 elanix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-August 09

error message in browser

Posted 01 October 2009 - 08:53 AM

HI...just wanna know this error i've got whenever I hit my login button to log in Admin page , and i was redirect in this page, which is I can't figure out what's wrong, i've already checked my php code for my logincheck and I still can't see whats wrong... what's this error message means?...

thanks



---THIS IS THE ERROR MESSAGE IN MY BROWSER----

This webpage has a redirect loop

The webpage at http://localhost/iCrome/adminhome.php has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

 

This post has been edited by elanix: 01 October 2009 - 08:54 AM


Is This A Good Question/Topic? 0
  • +

Replies To: error message in browser

#2 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: error message in browser

Posted 01 October 2009 - 08:59 AM

means something is not right with your headers ( or other method of redirecting )

Maybe post up some code to see whats going on
Was This Post Helpful? 0
  • +
  • -

#3 elanix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-August 09

Re: error message in browser

Posted 01 October 2009 - 01:49 PM

Thanks for the reply :D

here's my code




logincheck.php


<?php 	
		$username=$_POST['username'];
		$password=$_POST['password'];
			
			if($username!="" || $password!=""){
				
				include("config.php");
	
					$result=mysql_query("SELECT * FROM students WHERE username='$username' AND password='$password'")or die(mysql_error());
					$num=mysql_num_rows($result);
				
				//echo $num;
				
				if($num==1){
				session_start();
				$_SESSION['studentID']=mysql_result($result,0,'studentID');
				  header("location: studenthome.php");
					
				}
					
				elseif($num<1){
					$result=mysql_query("SELECT * FROM facilitators WHERE username='$username' AND password='$password'")
					or die(mysql_error());
					$rowcount=mysql_num_rows($result);	
					
						if($rowcount==1){
							session_start();
							$_SESSION['facilitatorID']=mysql_result($result,0,'facilitatorID');
								header("location: facilitatorhome.php");
						}
						elseif($rowcount<1){
							$result=mysql_query("SELECT * FROM employees WHERE username='$username' AND password='$password'")	
							or die(mysql_error());
							$rowcount=mysql_numrows($result);
								
								if($rowcount==1){
								session_start();
								$_SESSION['employeesID']=mysql_result($result,0,'employeesID');
									header("location: adminhome.php");														
								}
							
								else{
									 
									 header("refresh: 0;login.php");
									 
									?>
										<script language="javascript">
											alert("Invalid Username or Password");
										
										</script>
																		   									
									<?php
									
									}
									
								}
			
						}	
				//}		
			
			
			?>	 





index.php




<body>

	  <div class="wrapper">
		  <div class="container header borderBottom">
			  <div class="left border">
				<img src="images/i-crome_icon.png" alt="" width="120" height="120" /></div>
			  <!--left-->
			<div class="left">
					<div class="prepend-1 prepend-top">
						<h3>Integrated Communication Resource Object Multimedia Environment</h3>
					</div><!--prepend-->
			</div>
   		</div><!--container-->
		<div class="container">
			<div class="inlineLink separated right">
				  <ul>
						<li><a href="index.php">Home</a></li>
					  <li><a href="#">Help</a></li>
					  <li class="last"><a href="#">About us</a></li>
				  </ul>
			 </div>
		</div>
		<div class="container">
			<div class="prep span-8 colborder" >
				<h3>Login</h3>
				<form id="dummy1" action="logincheck.php" method="post">	
				  <fieldset>   
					<p>
					  <label for="dummy1">Username</label>
					  <input type="text" class="text" id="dummy1" name="username">
					</p>	
					<p>
					  <label for="dummy3">Password</label>
					  <input type="password" class="text" id="dummy3" name="password">
					</p>	
					<p class="prepend-top">
					  <input type="submit" value="Login">
					</p>	
					
				  </fieldset>
				  <p><a href="registration.php">Register Here</a> Not yet a member?</p>
				</form>



Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: error message in browser

Posted 01 October 2009 - 02:17 PM

Maybe try simplifying your script a bit ... with that many conditional statements linked like that its kinda hard to debug ... maybe something like this for the logincheck

<?php 
	session_start();
	include("config.php");
	$username = $_POST['username'];
	$password = $_POST['password'];
	
	if($username == "" || $password == ""){
		echo '<script language="javascript">
				alert("Username or password left blank.");
				window.location.href = "login.php";
			</script>';
		die;
	}	
	
	$tables = array(
		// table name			destination			idname
		"students"		=>	array("studenthome.php","studentID"),
		"facilitators"	=>	array("facilitatorhome.php","facilitatorID"),
		"employees"		=>	array("adminhome.php","employeesID")
	};
	
	foreach ($tables as $tablename => $information) {
		$query = "SELECT * FROM $tablename WHERE username='$username' AND password='$password'";
		$result = mysql_query($query)or die(mysql_error());
		$num = mysql_num_rows($result)l
		if ($num == 1) {
			// we found a match set a session variable
			$_SESSION[$information[1]] = mysql_result($result,0,$information[1]);
			// now redirect to where you want to go
			header("Location: " . $information[0]);
			// kill the script
			die;
		}
	}
	
	// if we made it here means no matches were found in the table queries
	echo '<script language="javascript">
			alert("Invalid username or password.");
			window.location.href = "login.php";
		</script>';
	die;
?>



its basically the exact thing you were doing except in a loop ... the query of the tables is in the same order .. and if it finds a match we win ... if not alert the user and return to login ... maybe this will help with debugging as well

as a note .. you look like your storing a plain password in the database, this would not be recommended and SOME sort of hashing/encrypting should really be implemented before going live with this ... as well as some sanitizing of the user inputs ... if your config.php file creates a mysql connection you should have the mysql_real_escape_string available to you

This post has been edited by RPGonzo: 01 October 2009 - 02:21 PM

Was This Post Helpful? 1
  • +
  • -

#5 elanix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-August 09

Re: error message in browser

Posted 01 October 2009 - 08:02 PM

my config.php, inside that i've got there my database connection and i just include it. in my codes. and another thing what's the use of mysql_real_escape_string?

thanks so much!
Was This Post Helpful? 0
  • +
  • -

#6 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: error message in browser

Posted 02 October 2009 - 06:12 AM

mysql_real_excape_string is basically a way to "sanitize" your user inputs, helps to minimize any malicious data that someone would try to enter.

using it is as simple as calling it on your inputs ...

$username = mysql_real_escape_string($_POST['username']);
	$password = mysql_real_escape_string($_POST['password']);



now be aware if the mysql_connection is not called before trying to use it it WILL throw a error but as long as you have your config included first you should be good ...

By chance did the error go away about your redirecting?
Was This Post Helpful? 0
  • +
  • -

#7 izrafel  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 95
  • Joined: 24-July 09

Re: error message in browser

Posted 02 October 2009 - 06:21 AM

from what i can see from the error,the problem is the following, you are creating a infinite redirect loop. for example,
1.you show the user the form
2.he types in the data
3.you validate
4.you redirect to somewhere
5.now that you are here, for some reason you redirect to login page
6.in log in page you see that you have the user input, you redirect to 3. and close the loop :)
now i will take a look at the code.and see what the problem is.(if i can see it of curse).
edit:
please post the adminhome.php code.its seems that there is the error.

This post has been edited by izrafel: 02 October 2009 - 06:55 AM

Was This Post Helpful? 0
  • +
  • -

#8 elanix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-August 09

Re: error message in browser

Posted 02 October 2009 - 08:53 AM

good evening RPGonzo , thanks for explaining it, actually it is my first time to encountered mysql_real_escape_string, as a beginner in php, im still havin' difficulties in understanding some codes.but im glad i'm enjoying debugging my errors which i learned from my errors...and about the redirecting from my 3 php pages in adminhome,facultyhome,studenthome, i just neglect the header..hmm wrong header declaration..so the problem is not in my logincheck.:)) it lies in my the 3 pages i've mentioned.

but isn't ok if I ask another question from you mr.RPGonzo?..a bit shy coz i hope you don't look at me as so innocent in php...and being honest I want to learn more in php so i really have alot of questions bothering me..

thanks again! hope u reply.


Thanks for the help...I already resolved the error redirecting...


thanks so much! :))
Was This Post Helpful? 0
  • +
  • -

#9 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: error message in browser

Posted 02 October 2009 - 09:04 AM

Ask away ... would be best to just continue posting your questions and if i don't know/find the answer for you im sure someone else will chime in to help :)
Was This Post Helpful? 0
  • +
  • -

#10 elanix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-August 09

Re: error message in browser

Posted 02 October 2009 - 09:17 AM

I've got my file upload here..and created to upload files,images
but I just can't make it, to display image..for example if I upload image i just want to display it in my pages included with some text but can't display it, it only inserted in my database...that's my problem.


here's my code


<?php
$allowed = array("jpeg","gif","png","bmp", "jpg");  
?>

<form action="" method="post" enctype="multipart/form-data">
Choose file to upload <input name="upload" type="file">
<br><br><input name="sb" id="sb" value="Upload" type="submit">
</form>

<?php
include("config.php");

	if(isset($_POST['sb'])) {
	
	//check for valid extension
	$pathInfo = pathinfo($_FILES["upload"]["name"]);
	//$extension = $pathInfo['extension'];
	$allowed = array("jpeg","gif","png","bmp", "jpg");
	$timestamp=date("Y-m-d H:i:s");
	
//choose directory/foolder to place the file in
$dir = "uploadFolder";
			
			
		
		//if(!in_array($allowed)) die("Extension not allowed!");
		if(move_uploaded_file($_FILES['upload']['tmp_name'], "$dir/".$_FILES['upload']['name'])) {
			
			print "Your new file can be viewed/download at <input name=\"newfile\" 			
			value=\"http://$_SERVER[HTTP_HOST]/$dir/".$_FILES['upload']['name']."\" type=\"text\" 		
			style=\"width: 300px\">";
		}
				
				else{
		echo"Invalid Input";
					  }
	
include("config.php");

		 $sql = "insert into files values (null, '".htmlentities($_FILES['upload']['name'])."', 	
		 		'now()', '$_SERVER[REMOTE_ADDR]')";
		 $rs = mysql_query($sql);
		 
		 print mysql_error();
		}
?>








Thanks again...:)) your help was really a big solution in my worries.
Was This Post Helpful? 0
  • +
  • -

#11 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: error message in browser

Posted 02 October 2009 - 09:40 AM

I would say the simplest way to display the image back to the user is just a simple HTML <img> ... because you verify if the file was indeed uploaded and moved to your folder you could echo a img tag with the correct src attribute and it should display correctly

if(move_uploaded_file($_FILES['upload']['tmp_name'], "$dir/".$_FILES['upload']['name'])) {
		   
	print "<img src=\"$dir/".$_FILES['upload']['name']."\" alt=\"Uploaded Image\" /><br/>
	Your new file can be viewed/download at <input name=\"newfile\"			
	value=\"http://$_SERVER[HTTP_HOST]/$dir/".$_FILES['upload']['name']."\" type=\"text\"		
	style=\"width: 300px\">";
}



granted you might have to tweak the image src to get it to work this was just a example of outputting the image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1