Jump to content

Recommended Posts

Ive never worked with cookies before.... so here it goes....

 

<?
include("./config.php");

if ($login[id] && !is_numeric($login[id])) {
error("You have specified an Invalid Login ID!"); }

check_login($login);

switch($action){

//DEFAULT - SET COOKIES

default:
cookies($login,$retnmsg);
break;
}


function check_login($login){
global $config;

if(!mysql_num_rows(mysql_query("SELECT id FROM teams WHERE id='$login[id]' AND password='$login[pass]'"))){
$out[body].="

<center>
<table width='70%' border='0' cellspacing='1' cellpadding='2' bgcolor='#000000'>
<form method='post'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'>
<strong>Login</strong>";
if($login[fail]){
$out[body].=" <font color='#FF0000' size='1'>(Incorrect Login)</font>";
}

if(isset($_COOKIE["id"])){
$out[body].="
<center>
<table width='90%' border='0' cellspacing='1' cellpadding='1' bgcolor='#000000'>
<tr>
<td width='100%' valign='center' align='left'  background='$config[bg]'>
<strong>Error!</strong></td></tr>
<tr><td width='100%' valign='center' align='center' bgcolor='$config[altcolora]'>
You are already logged in!</td></tr>
</table></center>";
}else{
$out[body].="
</td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'>Account ID</td>
<td width='60%' valign='center' align='center'><input type='text' name='login[id]'  class='input' value='$login[id]' size='25' maxlength='10'></td>
</tr>
<tr bgcolor='$config[altcolora]'>
<td width='40%' valign='center' align='left'>Password</td>
<td width='60%' valign='center' align='center'><input type='password' name='login[pass]'  class='input' value='' size='25' maxlength='10'></td>
</tr>
<tr bgcolor='$config[altcolora]'>
<td width='40%' valign='center' align='left'>Remember</td>
<td width='60%' valign='center' align='center'><SELECT NAME='login[length]'>
<option value='600'>10 Minutes</option>
<option value='3600'>1 Hours</option>
<option value='86400'>1 Day</option>
<option value='604800'>1 Week</option>
<option value='19353600'>1 Month</option>
</SELECT></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='100%' valign='top' align='right' colspan='2'>
<div align='left' style='float:left'>Not registered? <a href='./join.php'>Join now!</a></div>
<input type='hidden' name='login[fail]' value='1'>
<input type='submit' name='submit' value='Login >>'></td>
</form>
</tr>
</table><br /><br /><br /><br />
";

$out[body].="
<table width='70%' border='0' cellspacing='1' cellpadding='2' bgcolor='#000000'>
<form method='post' action='./forgotpw.php'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'>
<strong>Forgot Password?</strong>
</td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'>Account ID</td>
<td width='60%' valign='center' align='center'><input type='text' name='login[id]'  class='input' value='' size='25' maxlength='10'></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='100%' valign='top' align='right' colspan='2'>
<input type='hidden' name='login[fail]' value='1'>
<input type='submit' name='submit' value='Resend >>'></td>
</form>
</tr>
</table>
</center>";
}

include("$config[html]");
exit;
}
}


function cookies($login,$retnmsg){
setcookie("id", "$login[id]", time()+$login[length]);
setcookie("pass", "$login[pass]", time()+$login[length]);


global $config;

check_login($login);

$zonefind=mysql_query("SELECT * FROM teams WHERE id='$login[id]'");
$zonefind=mysql_fetch_array($zonefind);

$team=mysql_query("SELECT * FROM teams WHERE id='$login[id]' AND password='$login[pass]'");
$team=mysql_fetch_array($team);

$ladder=mysql_query("SELECT * FROM ladders WHERE id='$team[ladderid]' AND active='1'");
$ladder=mysql_fetch_array($ladder);

if(!$ladder[name]){
error("This ladder is temporarily closed.");
}

$out[body].="
<META HTTP-EQUIV='refresh' content='3;URL=$config[scripturl]/index.php'> 
<center>
<table width='90%' border='0' cellspacing='1' cellpadding='1' bgcolor='#000000'>
<tr>
<td width='100%' valign='center' align='left'  background='$config[bg]'>
<strong>Sucessfull login!</strong></td></tr>
<tr><td width='100%' valign='center' align='center' bgcolor='$config[altcolora]'>
Login information set, please wait while we redirect you.</td></tr>
</table></center>";



include("$config[html]");
}




?>

 

Its coming up with a header error because its not setting he cookie first thing in the bage but how can i get the cookie to set first.?

Link to comment
https://forums.phpfreaks.com/topic/63783-noobie-question/
Share on other sites

The error is pretty self explanatory. You need to set cookies before any output is sent to the browser. Since I do not see HTML, or HEAD tags in that code I am assuming that those are created in another page before this one is run.

 

As soon as you do an echo, print or other statement that writes content to the page, you cannot set a cookie. You need to plan out your page structure accordingly. Without, having to change your structure drastically I would suggest that where you are creating the head of your document you write the content to a variable. Then, after you set your cookies on this page you can write the head variable to the page.

Link to comment
https://forums.phpfreaks.com/topic/63783-noobie-question/#findComment-317896
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.