...

View Full Version : errors with login script



Bob42
11-04-2007, 05:04 AM
I'm creating a login script for something, but I'm having a few problems with it. Whenever I log in, I get errors.


Warning: session_register(): Cannot send session cookie - headers already sent by (output started at /home/pokethi1/public_html/pokedex/24r/php/authentication.php:1) in /home/pokethi1/public_html/pokedex/24r/php/authentication.php on line 15

Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at /home/pokethi1/public_html/pokedex/24r/php/authentication.php:1) in /home/pokethi1/public_html/pokedex/24r/php/authentication.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/pokethi1/public_html/pokedex/24r/php/authentication.php:1) in /home/pokethi1/public_html/pokedex/24r/php/authentication.php on line 17

Here's the authentication.php script where everything is in. I have the form for entering the username and password on a separate HTML page, but I don't think you need that.


<?php

mysql_connect("localhost", "username", "password")or die(mysql_error());
mysql_select_db("database")or die(mysql_error());

$username=$_POST['username'];
$password=$_POST['password'];

$sql="SELECT * FROM admins WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("username");
session_register("password");
header("location:login_success.php");
}

else {
echo "<center><font size='5'>Stop trying to hack the PokÚdex!</font><br><img src='463_berobelt.jpg'>";
}

?>

Yes, I edited out the mysql_connect info. What's wrong with the script?

Inigoesdr
11-04-2007, 05:16 AM
You have a space, or some other character(s) before your <?php tag at the beginning of your file.

JustBlaze
11-04-2007, 05:16 AM
Try putting session_start(); at the top, Not sure if it will help
but it's worth a try.

Bob42
11-04-2007, 05:32 AM
There aren't any spaces before the <?php tag.

I replaced <?php with <?php session_start(); and I still get the same errors.

Corey
11-04-2007, 05:44 AM
Hey,

session_start(); needs to be the second line and then instead of session_register do $_SESSION['username'] = $username; $_SESSION['password'] = $password;.


<?php
session_start();

mysql_connect("localhost", "username", "password")or die(mysql_error());
mysql_select_db("database")or die(mysql_error());

$username=$_POST['username'];
$password=$_POST['password'];

$sql="SELECT * FROM admins WHERE username='".$username."' and password='".$password."'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
header("location:login_success.php");
}

else {
echo "<center><font size='5'>Stop trying to hack the PokÚdex!</font><br /><img src='/463_berobelt.jpg' alt='Berobelt' />";
}

?>

CFMaBiSmAd
11-04-2007, 05:46 AM
This is a pretty common problem, I have answered it a number of times in this Forum -

My guess is that you have edited or opened/saved this file using an editor that saved it as a UTF-8 or Unicode file.

Make sure the file is saved in ANSI/ASCII mode.

Bob42
11-04-2007, 06:00 AM
Ah yes, thank you. That did the trick.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum