http://ouraubie.com

try logging in my site using (username: user password: user). the script do not redirect. my code is:

header('Location: ../index.php');

i tried using my "Location: ".URL."" but stil it doesn't work here.

Member Avatar
diafol

if you're in the root public directory, the ../ will try to go to the parent directory, which I assume does not contain the index.php. Just take off the ../

nope. i tried the meta tag and it works with the URL. the problem is the header script.

this works:

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index.php">';

but this, do not:

header("Location: ../index.php");
Member Avatar
diafol

I had a look at your source code (html). I'm afraid it's all to hell. I shouldn't think that that's the cause, but is the header() at the top of the page before any html output?

There's something really odd going on. I logged in, then again in the weird white page and got this:


Have you got include files?

I don't understand why you'd have a meta tag in a form handling page anyway - the purpose of a form handler is that it just processes and redirects.

yup cuz my form action is = view/login.php?act=login
and under my login php under the login case, there is a header script which doesn't work

another thing about what you're saying about meta tags,
read my post. i just tried it but i use header()

Member Avatar
diafol

another thing about what you're saying about meta tags,
read my post. i just tried it but i use header()

I did. I was just commenting that your html is badly formed and that the meta tag shouldn't have been there anyway. No big deal.
You should post your code, otherwise we're just guessing.

If you're having a big trouble then use

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index.php">';

like what Rhamines said but I'd still recommend you use header instead of meta tag

<?php
session_start();
error_reporting(0);
?>

<form action="view/login.php?act=login" method="POST">
	<table width=900 border=0 cellpadding=0 cellspacing=0 align=center>
	<tr background=images/header_top.png><td>
	<div align=right><font size=2 style="color: #cccccc">

<div align=right>
Username
<input type=text name=user size=10>
Password
<input type=text name=pass size=10>
<input type=submit value=Login>
<a style="color: #EEEEEE" href="../index.php?page=reg_user">Signup</a>!
&nbsp;&nbsp;
</div></font>
</form>

<?php

$act = $_GET['act'];
$un = $_POST['user'];
$pw = $_POST['pass'];

switch($act)
{
	case 'login':

		
		$con = mysql_connect("localhost", "inhsphco_root", "root");
		mysql_select_db("inhsphco_ouraubie");
		$login = mysql_query("SELECT * FROM users WHERE
		(user = '" .mysql_real_escape_string($un). "') and
		(pass = '" .mysql_real_escape_string($pw). "')");
		$session = session_id();
		
		mysql_query("SELECT * FROM members_online");

		$count = mysql_num_rows($login);
		$type_row = mysql_fetch_array($login);
		if($count == 1)
		{
			session_register(un);
			session_register(pw);
						
			$_SESSION['type'] = $type_row['type'];
			$_SESSION['uid'] = $type_row['uid'];
			
			mysql_query("INSERT INTO members_online(
			id, user, session)
			VALUES
			('$type_row[uid]', '$type_row[user]', '$session')
			");
			
			header("Location: ../index.php");
			
		}
		else
		{	
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index.php">';
		}

	break;
	
	case 'logout':

		session_start();
		session_destroy();
		
		$uid = $_SESSION['uid'];
		$con = mysql_connect("localhost", "inhsphco_root", "root");
		
		mysql_select_db("inhsphco_ouraubie");
		mysql_query("SELECT * FROM members_online");
		mysql_query("DELETE FROM members_online WHERE id = '$uid'");
		header("Location: ../index.php");
		
	break;
	
	default:
	break;
}
?>

If you're having a big trouble then use

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index.php">';

like what Rhamines said but I'd still recommend you use header instead of meta tag

meta tags shows different way like what header. i prefer header. even you put the '0'(time to refresh) still there is 1second delay

Member Avatar
diafol

header cannot appear after html output. Place all your php code ABOVE the html.

oh good good thank you hehe :) i'll try

header cannot appear after html output. Place all your php code ABOVE the html.

wow thank you so much :) it worked. sorry i don't know some rules in php.

Member Avatar
diafol

ok - mark this thread as solved - see the link below the edit box

Wow he didn't come back to ever mark this thread as solved

First of all use header at the top before html tag because it work fine then and use error_reporting at last when you get the code perfectly in working condition becuase it hides your all error and then you wont known where the problem is.try this code and answer me if you any problem i will there to help you.Thanks

<?php
 session_start();

// error_reporting(0);

if(isset($_POST))

{

$act = $_GET['act'];
$un = $_POST['user'];
$pw = $_POST['pass'];
 
switch($act)
{
case 'login':
 
 
$con = mysql_connect("localhost", "inhsphco_root", "root");
mysql_select_db("inhsphco_ouraubie");
$login = mysql_query("SELECT * FROM users WHERE
(user = '" .mysql_real_escape_string($un). "') and
(pass = '" .mysql_real_escape_string($pw). "')");
$session = session_id();
 
mysql_query("SELECT * FROM members_online");
 
$count = mysql_num_rows($login);
$type_row = mysql_fetch_array($login);
if($count == 1)
{
session_register(un);
session_register(pw);
 
$_SESSION['type'] = $type_row['type'];
$_SESSION['uid'] = $type_row['uid'];
 
mysql_query("INSERT INTO members_online(
id, user, session)
VALUES
('$type_row[uid]', '$type_row[user]', '$session')
");
 
header("Location: ../index.php");
 
}
else
{
header("Location: ../index.php");
}
 
break;
 
case 'logout':
 
session_start();
session_destroy();
 
$uid = $_SESSION['uid'];
$con = mysql_connect("localhost", "inhsphco_root", "root");
 
mysql_select_db("inhsphco_ouraubie");
mysql_query("SELECT * FROM members_online");
mysql_query("DELETE FROM members_online WHERE id = '$uid'");
header("Location: ../index.php");
 
break;
 
default:
break;
}

}
?>

<html>
<body>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<table width=900 border=0 cellpadding=0 cellspacing=0 align=center>
<tr background=images/header_top.png><td>
<div align=right><font size=2 style="color: #cccccc">
 
<div align=right>
Username
<input type=text name=user size=10>
Password
<input type=text name=pass size=10>
<input type=submit value=Login>
<a style="color: #EEEEEE" href="../index.php?page=reg_user">Signup</a>!
&nbsp;&nbsp;
</div></font>
</form>

</body>
</html?
Member Avatar
diafol

> wow thank you so much it worked.

:)

bit of work there extemer

i didnt get what you said @ardav

Well as I see it there is something really wrong how you wrote your code.

error_reporting(0);

Remove this... (Warnings are there for a reason. Think more about it)

Take a look closer:

case 'login': ... header("Location: ../index.php");

My guess is a Warning: headers already sent is issued. Which is why your header(); does not work.

Solution:
Move all the HTML at the bottom of your code. DO NOT echo, print or whatever output before your header.

Reference

EDIT: if I knew extemer is going to answer the same I'd never waste my time.. :D :D

Member Avatar
diafol

> header cannot appear after html output. Place all your php code ABOVE the html.

This has already been answered.