Current location: Hot Scripts Forums » Programming Languages » PHP » Cookie problem, not being set.


Cookie problem, not being set.

Reply
  #1 (permalink)  
Old 12-10-06, 01:53 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
Cookie problem, not being set.

There was no error message, there is a value for $user but still no cookie was set!
PHP Code:

setcookie ("user"$user$time+3200); 

      
setcookie ("pass"md5('super secret salt that no one knows'$pass), $time+3200);
      
$success "Y";
      
$content 'You\'ve success fully logged into your account as <strong>'$_COOKIE['user'] .'</strong>. Please <a href=index.php>click here</a> if the page does not automatically refresh within 5 seconds.'
As you can see, it is supposed to echo the user cookie, but nothing was displayed... Any ideas on why?
Reply With Quote
  #2 (permalink)  
Old 12-10-06, 02:27 PM
manilodisan manilodisan is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Scripts and programs

check if it writes something in the cookie folder
__________________
Scripts and programs
Reply With Quote
  #3 (permalink)  
Old 12-10-06, 02:28 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
No it didnt...

Nothing...
Reply With Quote
  #4 (permalink)  
Old 12-10-06, 03:09 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Assuming that the cookie was sent to the browser, it is not directly available within the same code that sets it until the page is refreshed or you browse to a different page and the headers are exchanged which is when the browser sends the cookie back to the web server and the $_COOKIE... variable becomes set.

Try putting this after your first opening php tag to see if there is a header problem -
PHP Code:

error_reporting(E_ALL); 

__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #5 (permalink)  
Old 12-10-06, 03:32 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
a few errors....

Code:
Notice: Undefined index: user in /home/lostonea/public_html/liquidsqueeze/logincheck.php on line 6

Notice: Undefined index: pass in /home/lostonea/public_html/liquidsqueeze/logincheck.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home/lostonea/public_html/liquidsqueeze/logincheck.php:6) in /home/lostonea/public_html/liquidsqueeze/processlogin.php on line 19

Warning: Cannot modify header information - headers already sent by (output started at /home/lostonea/public_html/liquidsqueeze/logincheck.php:6) in /home/lostonea/public_html/liquidsqueeze/processlogin.php on line 20

Notice: Undefined index: user in /home/lostonea/public_html/liquidsqueeze/processlogin.php on line 22
logincheck.php
PHP Code:

<?

 error_reporting
(E_ALL);
include(
'db.php');
// Mon. Sept 02, 1992 1:55 pm
$date date("D. M dS, Y h:i a");
$time=time();
$user $_COOKIE['user'];
$pass $_COOKIE['pass'];
if(!
$pass || !$user){
    
$success "N";
    function 
get_access(){
            
$acess "N";
            return 
$acess;
    }
}else{
    
$get_login_checks mysql_query("SELECT * FROM members WHERE username='$user' AND password='$pass'") or die ("ERROR: "mysql_error() ."!"); 
    
$login_check mysql_num_rows($get_login_checks); 
    if(
$login_check == 0){
        function 
get_access(){
            
$acess "N";
            return 
$acess;
        }
        
$success="N";
    }else{
        
$playerinfo mysql_fetch_array($get_login_checks);
        
$success="Y";
        function 
get_access(){
            global 
$playerinfo;
            if(
$playerinfo[staff_level]==0){
                
//Normal member give no access
                
$access "N";
            }elseif(
$playerinfo[staff_level]==1){
                
//Forum Moderator
                
$access "F";
            }elseif(
$playerinfo[staff_level]==2){
                
// Managers get limited actions
                
$access "L";
            }elseif(
$playerinfo[staff_level]==3){
                
//Owner gets all admin actions
                
$access "Y";
            }else{
                
$access "N";
            }
//level
            
return $access;
        }
//get_access(); function
    
}
    
$access get_access();
}
?>
processlogin.php
PHP Code:

<?  

include('logincheck.php');
if(
$success=="Y"){
    
$content "Error: You are already logged in as <strong>$playerinfo[username]</strong>.";
}else{
    
$user $_POST['user'];
    
$pass $_POST['pass'];
    if (
$user && $pass) {
    
$pass2 md5('silverdasher'$pass);
    
$sel_mem mysql_query("SELECT * FROM members WHERE username='$user' && password='$pass2'")
;
     if (
mysql_num_rows($sel_mem)<=0) {
         
$content "Error: Could not be logged in! Either the <strong>username</strong> or <strong>password</strong> are incorrect!";
        
$success "N";
        
setcookie ("user"$user$time-3200); 
          
setcookie ("pass"md5('silverdasher'$pass), $time-3200);
     }else{
      
setcookie ("user"$user$time+3200); 
      
setcookie ("pass"md5('silverdasher'$pass), $time+3200);
      
$success "Y";
      
$content 'You\'ve success fully logged into your account as <strong>'$_COOKIE['user'] .'</strong>. Please <a href=index.php>click here</a> if the page does not automatically refresh within 5 seconds.';
     }
    }else{
        
$content 'Error: Fields cannot be left blank!';
    }
}
//logged in
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LiquidSqueeze.com</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>

<body>
<? include'header.php'?>
                    <table border="0" align="center" cellpadding="0" cellspacing="0">
                      <tr>
                        <td class="mcheader">Processing Login...</td>
                      </tr>
                      <tr>
                        <td class="maincbbg"><table width="97%" border="0" align="center" cellpadding="0" cellspacing="0">
                            <tr>
                              <td><?
                              
echo"$content";
                              
?></td>
                            </tr>
                        </table>
                        </td>
                      </tr>
                      <tr>
                        <td><img src="images/mcb_footer.gif" alt="footer" width="368" height="10" /></td>
                      </tr>
                          </table>
                          <?
                        
include('footer.php');
                        
?>
</body>
</html>
Reply With Quote
  #6 (permalink)  
Old 12-10-06, 03:55 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
Problem Solved!

Solved thanks... dont ask how, i have no clue lol

Last edited by stormshadow; 12-10-06 at 04:07 PM. Reason: FIXED!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
set cookie for subfolders hinch PHP 7 10-21-06 08:04 AM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
Cookie problem Tempestshade PHP 5 06-14-05 05:37 AM
Setting a cooke (time it expires) mcrob PHP 4 04-27-05 12:13 PM
Passing info between pages w/ URL HairySpider JavaScript 6 01-09-05 08:47 AM


All times are GMT -5. The time now is 05:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.