Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
setcookie function after verify not working
Old 09-25-2008, 12:46 AM setcookie function after verify not working
Skilled Talker

Posts: 69
Trades: 0
Hey,

I am using the setcookie function. However, how can you connect to the database, verify username and password. Then, set the cookie if all is well. You cannot setcookie after all of the code????

Code:
$xname=$_POST['xname'];
$xpass=$_POST['xpass'];
$self=$_SERVER['PHP_SELF'];
$referer=$_SERVER['HTTP_REFERER'];

sql connection and verification coding

setcookie( "xcookie" , $xuser, time()+36000 );
Please help.

Thanks,
Matt
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-25-2008, 02:07 AM Re: setcookie function after verify not working
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Calls to the setcookie() function must be done prior to any output to the client - any html or whitespace http://uk.php.net/setcookie.

You can avoid 'headers already sent' errors by outputting to the buffer prior to setting a cookie and then releasing output from the buffer to the client.
http://uk.php.net/manual/en/outcontrol.examples.php

Difficult to tell the problem as you dont detail your script.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-25-2008, 02:42 AM Re: setcookie function after verify not working
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You can send headers anywhere in your script. The only requirement is having absolutely no output before calling functions that send headers.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 09-25-2008, 09:35 PM Re: setcookie function after verify not working
Skilled Talker

Posts: 69
Trades: 0
Trying this but still not not setting cookie:

Code:
<?php 
$cookie1=$_POST[cookie1];
$cookie2=$_POST[cookie2];
$self=$_SERVER['PHP_SELF'];
$referer=$_SERVER['HTTP_REFERER'];
require('connecttothedb.inc.php');
$sql="SELECT * FROM xxx where cookie2=\"$cookie2\" and cookie1=\"$cookie1\" ";
$result = mysql_query($sql,$connection) or die("Couldn't connect to members database at this time from xxx.  Sorry for the inconvenience.  Please try again later.<br>To inform us of the problem, please send us an email to: <a  href='mailto:email'>email'</a>");
$num=mysql_numrows($result);
if($num!=0){setcookie("cookie1",$cookie1,time()+36000);
setcookie("cookie2",$cookie2,time()+36000);
setcookie("auth","ok");
$msg="<b>Welcome</b>";}
else
{echo ("You have an incorrect username or password.<br><br><a href='url'>Go Back To Login Page</a>"); 
exit();}
?>
Thanks,
Matt
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
Old 09-25-2008, 11:16 PM Re: setcookie function after verify not working
Extreme Talker

Posts: 177
Trades: 0
my guess is the require() function is producing output not allowing the setcookie functions to pass.

Last edited by kbfirebreather; 09-25-2008 at 11:16 PM.. Reason: changed now to not
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 09-25-2008, 11:45 PM Re: setcookie function after verify not working
Skilled Talker

Posts: 69
Trades: 0
thanks, that was it! It was the require!
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to setcookie function after verify not working
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.82515 seconds with 12 queries