Jump to content

Setting cookies?


iamnottheend

Recommended Posts

OK this seems like a really dumb question but i just can't get it to work.

 

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

if ($_POST['submit']) {
$sql="SELECT user_id FROM site_security WHERE user_name='$username' AND user_password='$password'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
setcookie("logedinuser","content", time() + 30000);
print "successfully logged into system.";
}
}

 

Error

 

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\mysql_connect.php:17) in C:\webs\test\Jason2\adminpanel\index.php on line 42

successfully logged into system.

 

Any idea what is causing this?

Link to comment
Share on other sites

Sorry, this is made using the smarty templating engine.

 

Apart from Smarty i have this...

 

<?php # Script 6.5 - mysql_connect.php

// This file contains the database access information. This file also establishes a connection to MySQL and selects the database.

// Set the database access information as constants.
DEFINE ('DB_USER', 'xxx');
DEFINE ('DB_PASSWORD', 'xxx');
DEFINE ('DB_HOST', 'xxx');
DEFINE ('DB_NAME', 'xxx');

// Make the connnection and then select the database.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
?>

 

Full index.php follows...

 

<?php
require '../../smarty/libs/Smarty.class.php';

#dbc
include ('../../mysql_connect.php');

$smarty = new Smarty;

# Constants
$smarty->assign('templates', 'templates/');
$smarty->assign('currentpage', $_SERVER['PHP_SELF']);

# Display Header
$smarty->display('header.tpl');


# Main News
$smarty->display('index.tpl');

# Template Files
$smarty->display('footer.tpl');



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

if ($_POST['submit']) {
$sql="SELECT user_id FROM site_security WHERE user_name='$username' AND user_password='$password'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
setcookie("logedinuser","content", time() + 30000);

print "successfully logged into system.";
//proceed to perform website’s functionality – e.g. present information to the user
}
}

?>

Link to comment
Share on other sites

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.