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
Old 05-25-2006, 05:00 PM cookie issues
Junior Talker

Posts: 1
Trades: 0
I am using cookies to store the login variables, but for some reason they are not logging the user in: http://www.syc0logy.com

PHP Code:
<?php

include('lib/conf/config.php'); 
include(
'lib/functions.php');

// user logout
if($login==2){
   
setcookie("username""",  time()-60*60"/"".syc0logy.com",0);
   
setcookie("password""",  time()-60*60"/"".syc0logy.com",0);
   
$userid=0$username=""$password="";
         
$userid=0;


// user login
if ($login==1) {
    
$pass encryption($username,$password);

$sql "SELECT * FROM users";
$result mysql_query($sql);
while(
$row mysql_fetch_array($result)) {
    
   if(
$username==$row['username'] && $pass==$row['password'] && $login!=2){
           
$userid $row['userid'];
           
$usegroup $row['usegroup'];
           
   } else{
       
           
$username "";
           
$pass "";
   }   
   
   
$un $row['username'];
   
$pw $row['password'];
   
}
   
//set cookies
   
if($login==&& $userid>0){
       
   
setcookie("username""$username"time()+60*60"/"".syc0logy.com" );
   
setcookie("password""$password"time()+60*60"/"".syc0logy.com" );
   
 }
 
}

?>

   
<html>

<head>
      <title>Syc0tests - Powered By: XBASE Online</title>
      <link rel="stylesheet" type="text/css" href="lib/css/style.css">
</head>

<body>
<table border="0" width="100%" id="table1">
        <tr>
                <td align=center>
                <table border=0 cellspacing=0 cellpadding=0 align=center width=760>
                <tr>
                <td>
                <p class=contest_small align=right>v1.2.5 &nbsp;&nbsp;&nbsp;<center>
                <img border="0" src="/images/top.jpg" width="760" height="285"></td></tr></table></td>
        </tr>
</table>
<br>
<table border=0 cellspacing=4 cellpadding=5 align=center width=760>
<tr>
<td colspan=2 width=760>
<? if($userid 0){ ?>

<!-- begin user status -->
<div class=welcome>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=contest_small align=right>

Welcome <?=$username?> [ <a href=index.php?op=login=2>logout</a> ]

</td>
  </tr>
</table>
<? } else { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=contest_small align=right>
<form action="index.php" method="post">
    <input type="hidden" name="login" value="1">
login: &nbsp; <input type=text name="username" size=10 value="" class=contest style="background-color:#2A2922; border:1px solid #C0C0C0"> &nbsp; 
password: &nbsp; <input type=password name="password" size=10 class=contest style="background-color:#2A2922; border:1px solid #C0C0C0"> &nbsp; 
<input type=submit value="login" class=submit>

<?
// Error if bad login
if($login == && $userid == 0) {

 echo 
"<br>Incorrect login information!&nbsp; Forgot Password? <a href=\"?op=forgotpasswd\">Click Here</a><br>";

} else {
    
 echo 
"<br>Don't have an account? Then <a href=\"?op=register\">Register Now!</a>";     
 
}
?>
</form>
</td></tr>
</table>
<? ?>
</td>
</tr>
<tr>
<td valign=top class=contest width=260>
<div id="mainmenu">
<b>MAIN MENU</b><br><br>
- <a href="?op=home">home</a><br>
- <a href="?op=blogs">blogs</a><br>
- <a href="?op=credits">credits</a><br>
- <a href="?op=sponsers">sponsors</a><br>
- <a href="?op=contact_us">contact us</a><br>
<p>&nbsp;</p>
<?php
    
if ($userid>0) {
    echo 
"<b>USER MENU</b><br><br>";

        echo 
"- <a href=?op=register>profile</a><br>";
        echo 
"- <a href=?op=blogs>blogs</a><br>";
        echo 
"- <a href=?op=pm>private messages</a><br>";
        echo 
"- <a href=?op=home&login=2>logout</a><br>";
    } else {
        
    }
?>
<p>&nbsp;</p>
</div>
</td>
<td class=contest valign=top align=left width=500>
    <div id="leftcol">
      <?php 
      
      
if(isset($op)) {
            if(
$op == 'home') {
                 
$op "home";
          }
          include(
$op.".php");
      } else {
          include(
"home.php");
     }
      
       
?>
    </div>
</td>
</tr>
</table>
    </div>
  </body>
</html>
xbase is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-27-2006, 03:17 PM Re: cookie issues
ChancesAre's Avatar
Skilled Talker

Posts: 84
Trades: 0
Where is $login comming from?

<? if($userid > 0){ ?> <- you need this stored somewhere. The value of $userid, should be stored as cookie or session, else you will login once and then once you click a page youre logged out again.

$login if the tries to login, but after the login it will still look for that variable again, there should be a check if username or pass in cookie are set and check if they match an acount in database, if they matchthen continue session.

Quote:
Originally Posted by xbase
I am using cookies to store the login variables, but for some reason they are not logging the user in: http://www.syc0logy.com

PHP Code:
<?php

include('lib/conf/config.php'); 
include(
'lib/functions.php');

// user logout
if($login==2){
   
setcookie("username""",  time()-60*60"/"".syc0logy.com",0);
   
setcookie("password""",  time()-60*60"/"".syc0logy.com",0);
   
$userid=0$username=""$password="";
         
$userid=0;


// user login
if ($login==1) {
    
$pass encryption($username,$password);

$sql "SELECT * FROM users";
$result mysql_query($sql);
while(
$row mysql_fetch_array($result)) {
    
   if(
$username==$row['username'] && $pass==$row['password'] && $login!=2){
           
$userid $row['userid'];
           
$usegroup $row['usegroup'];
           
   } else{
       
           
$username "";
           
$pass "";
   }   
   
   
$un $row['username'];
   
$pw $row['password'];
   
}
   
//set cookies
   
if($login==&& $userid>0){
       
   
setcookie("username""$username"time()+60*60"/"".syc0logy.com" );
   
setcookie("password""$password"time()+60*60"/"".syc0logy.com" );
   
 }
 
}

?>

   
<html>

<head>
      <title>Syc0tests - Powered By: XBASE Online</title>
      <link rel="stylesheet" type="text/css" href="lib/css/style.css">
</head>

<body>
<table border="0" width="100%" id="table1">
        <tr>
                <td align=center>
                <table border=0 cellspacing=0 cellpadding=0 align=center width=760>
                <tr>
                <td>
                <p class=contest_small align=right>v1.2.5 &nbsp;&nbsp;&nbsp;<center>
                <img border="0" src="/images/top.jpg" width="760" height="285"></td></tr></table></td>
        </tr>
</table>
<br>
<table border=0 cellspacing=4 cellpadding=5 align=center width=760>
<tr>
<td colspan=2 width=760>
<? if($userid 0){ ?>

<!-- begin user status -->
<div class=welcome>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=contest_small align=right>

Welcome <?=$username?> [ <a href=index.php?op=login=2>logout</a> ]

</td>
  </tr>
</table>
<? } else { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=contest_small align=right>
<form action="index.php" method="post">
    <input type="hidden" name="login" value="1">
login: &nbsp; <input type=text name="username" size=10 value="" class=contest style="background-color:#2A2922; border:1px solid #C0C0C0"> &nbsp; 
password: &nbsp; <input type=password name="password" size=10 class=contest style="background-color:#2A2922; border:1px solid #C0C0C0"> &nbsp; 
<input type=submit value="login" class=submit>

<?
// Error if bad login
if($login == && $userid == 0) {

 echo 
"<br>Incorrect login information!&nbsp; Forgot Password? <a href=\"?op=forgotpasswd\">Click Here</a><br>";

} else {
    
 echo 
"<br>Don't have an account? Then <a href=\"?op=register\">Register Now!</a>";     
 
}
?>
</form>
</td></tr>
</table>
<? ?>
</td>
</tr>
<tr>
<td valign=top class=contest width=260>
<div id="mainmenu">
<b>MAIN MENU</b><br><br>
- <a href="?op=home">home</a><br>
- <a href="?op=blogs">blogs</a><br>
- <a href="?op=credits">credits</a><br>
- <a href="?op=sponsers">sponsors</a><br>
- <a href="?op=contact_us">contact us</a><br>
<p>&nbsp;</p>
<?php
    
if ($userid>0) {
    echo 
"<b>USER MENU</b><br><br>";

        echo 
"- <a href=?op=register>profile</a><br>";
        echo 
"- <a href=?op=blogs>blogs</a><br>";
        echo 
"- <a href=?op=pm>private messages</a><br>";
        echo 
"- <a href=?op=home&login=2>logout</a><br>";
    } else {
        
    }
?>
<p>&nbsp;</p>
</div>
</td>
<td class=contest valign=top align=left width=500>
    <div id="leftcol">
      <?php 
      
      
if(isset($op)) {
            if(
$op == 'home') {
                 
$op "home";
          }
          include(
$op.".php");
      } else {
          include(
"home.php");
     }
      
       
?>
    </div>
</td>
</tr>
</table>
    </div>
  </body>
</html>
ChancesAre is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to cookie issues
 

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.10286 seconds with 12 queries