Jump to content

Recommended Posts

I have hosting with Godaddy.Com and I am having problems with sessions. I contacted them and the cannot figure out the problem. Here is the page I am working on http://www.classifiedsinhawaii.com/Login101/login-box.php

when you login the session error message comes up. Has anyone seen this message before ?

 

regards,

usawh

Link to comment
https://forums.phpfreaks.com/topic/202325-problem-with-sessions/
Share on other sites

Here is the code

 

<?session_start();

 

$username = $_POST['username'];

$password = $_POST['password'];

 

if ($username&&$password)

 

{

 

$connect = mysql_connect('server','user','password') or die("couldn't connect ");

mysql_select_db('hilo102') or die ("couldn't find db");

 

$query = mysql_query(" SELECT * FROM users WHERE username='$username'");

 

$numrows = mysql_num_rows($query);

 

if ($numrows!=0)

 

{

 

while ($row = mysql_fetch_assoc($query))

 

{

 

$dbusername = $row['username'];

$dbpassword = $row['password'];

 

}

 

if ($username==$dbusername&&$password==$dbpassword)

 

{

echo'you are logged in click <a href="http://www.classifiedsinhawaii.com/Post-Ads/post-ads.php">here</a> to post ad';

$_SESSION['username']=$username;

 

}

 

 

else

    echo'incorrect password';

 

 

}

else

    die('That user does not exist');

   

echo $numrows;

 

 

 

}

 

else

    die (' Please enter an username and password  !');

 

 

?>

 

 

 

 

Here is the code

 

<?session_start();

 

$username = $_POST['username'];

$password = $_POST['password'];

 

if ($username&&$password)

 

{

 

$connect = mysql_connect('server','user','password') or die("couldn't connect ");

mysql_select_db('hilo102') or die ("couldn't find db");

 

$query = mysql_query(" SELECT * FROM users WHERE username='$username'");

 

$numrows = mysql_num_rows($query);

 

if ($numrows!=0)

 

{

 

while ($row = mysql_fetch_assoc($query))

 

{

 

$dbusername = $row['username'];

$dbpassword = $row['password'];

 

}

 

if ($username == $dbusername && $password == $dbpassword)

 

{

echo'you are logged in click <a href=\"http://www.classifiedsinhawaii.com/Post-Ads/post-ads.php\">here</a> to post ad'; //Must add backslashes

$_SESSION['username']=$username;

 

}

 

 

else

    echo'incorrect password';

 

 

}

else

    die('That user does not exist');

   

echo $numrows;

 

 

 

}

 

else

    die (' Please enter an username and password  !');

 

 

?>

 

Cleaned up your code a bit.

<?php
session_start();

/*
I would recommend reloacting the database connect code to another file and using require_once("filename") to include the file
*/

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

if ($username && $password)
{
$connect = mysql_connect('server','user','password') or die("couldn't connect ");
mysql_select_db('hilo102') or die ("couldn't find db");
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'");
$numrows = mysql_num_rows($query);

if ($numrows != 0)
{
	while ($row = mysql_fetch_assoc($query))
	{
	/* I would recommend hashing the password on both sides to prevent hackers from getting the password. */
	$dbusername = $row['username'];
	$dbpassword = $row['password'];
	}

	if ($username == $dbusername && $password == $dbpassword)
	{
	$_SESSION['username'] = $username;
	echo "You are logged in click <a href=\"http://www.classifiedsinhawaii.com/Post-Ads/post-ads.php\">here</a> to post an Ad";
	}

	else
	{
	    echo "Incorrect Password";
	}
}

else
{
    die("That User does not Exist");
    }
    
echo $numrows;

}

else
{
    die (" Please enter an username and password !");
    }
?>

 

Hi,

 

Could it be something with the php.ini file ?

 

Here is the file:

 

register_globals = off

allow_url_fopen = on

expose_php = Off

max_input_time = 60

variables_order = "EGPCS"

extension_dir = ./

upload_tmp_dir = /tmp

precision = 12

SMTP = relay-hosting.secureserver.net

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="

 

 

[Zend]

zend_extension=/usr/local/zo/ZendExtensionManager.so

zend_extension=/usr/local/zo/4_3/ZendOptimizer.so

 

 

There must be some balnk space before <?php tag

 

Try to remove it, and even if it doesn't solved try after enabling error_reporting(E_ALL) because there may be some notice in your code.

 

If that also doesn't solve your problem then write ob_start() at first line.

You are getting output from line 1 of your file. Since the php code on line 1 is not producing any output, that means that either you have some characters in your file before the <?php tag or your file has been saved with UTF-8 encoding and the BOM (Byte Order Mark) characters that your editor placed at the start of the file is the output that is occurring that is preventing the header from working.

 

Insure that there are no actual characters before the <?php tag in your file and insure that you save the file without the BOM if you are intentionally saving the file as a UTF-8 encoded file or save the file as an ANSI encoded file.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.