PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 2:08 am
With the following the cookie is not being set.. I dont have a clue
have the i-net security of browser on the most lowest as possible..
still echo returned, Cant set cookie.
Code: Select all
<?
setcookie ("USERNAME", $_POST['username']);
setcookie ("PASSWORD", $_POST['password']);
if(isset($_COOKIE['USERNAME']))
{
include_once ("auth.php");
include_once ("authconfig.php");
$username = $_POST['username'];
$password = $_POST['password'];
$Auth = new auth();
$detail = $Auth->authenticate($username, $password);
if ($detail==0)
{
?><HEAD>
<SCRIPT language="JavaScript1.1">
<!--
location.replace("<? echo $failure; ?>");
//-->
</SCRIPT>
</HEAD>
<?
}
elseif ($detail==1) {
?>
<HEAD>
<SCRIPT language="JavaScript1.1">
<!--
location.replace("<? echo $success; ?>");
//-->
</SCRIPT>
</HEAD>
<?
}
}
else
{echo 'couldnt set cookie';
}
?>
Last edited by
ol4pr0 on Mon Jun 21, 2004 2:15 pm, edited 2 times in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 21, 2004 2:11 am
you are aware that most cookies take a page refresh to become available to a page yes?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 2:15 am
Yes.. i do however on refresh or when redirecting it to antoher page.. the var $_COOKIE['USERNAME'] is still undefined.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 2:21 am
Thats why i put in that if(isset
That after many tries and differant refreshes, so i thought maby something wrong with the code
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 21, 2004 2:28 am
for fun.. try this in it's own page:
Code: Select all
<?php
if(!isset($_GET['refresh']))
{
header('Location: '.$_SERVER['SCRIPT_NAME'].'?refresh=0&USERNAME='.(isset($_REQUEST['USERNAME'])?$_REQUEST['USERNAME']:'george'));
}
elseif(($ref = $_GET['refresh']) < 5)
{
header('Set-Cookie: USERNAME='.$_REQUEST['USERNAME'].'; Version = 1;');
header('Location: '.$_SERVER['SCRIPT_NAME'].'?refresh='.($_GET['refresh']+1).'&USERNAME='.$_REQUEST['USERNAME']);
echo 'refresh '.$_GET['refresh'];
flush();
}
else
{
die('Couldn''t set cookie in 5 attempts!');
}
?>
[edit]oops.. made a tiny boo-boo in the die.. fixed.[/edit]
Last edited by
feyd on Mon Jun 21, 2004 2:34 am, edited 3 times in total.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 2:29 am
I will, could be some fun...
i let u know what happend..
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 2:39 am
Coulnt set cookie in 5 times is the result.
EDIT:
actually
Couldn't set cookie in 5 attempts!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 21, 2004 2:42 am
sounds like your browser isn't accepting the cookies. You may need to fiddle with your settings some more..
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 3:39 am
WEll i tried something very simple
Code: Select all
$cookiename='name';
$value='some';
setcookie($cookiename,$value);
echo $_COOKIE['name'];
#Did work on refresh.
What u had up there.. didnt work.
What i have i will show u, i have a couple pages.
index where the login is located, after the login it goes to the authenticate.php which has the code above.
the auth.php has this.
Code: Select all
<?
class auth{
var $HOST = "localhost";
var $USERNAME = "root";
var $PASSWORD = "";
var $DBNAME = "woning";
function authenticate($username, $password) {
$connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD);
$SelectedDB = mysql_select_db($this->DBNAME);
$sql = mysql_query("SELECT * FROM users WHERE login='$username'", $connection);
$data = mysql_fetch_array($sql);
$encrypted_password = $data['password'];
$password = crypt($_POST['password'], $encrypted_password);
if ($password == $encrypted_password) {
return 1;
}else{
return 0;
}
$UpdateRecords = "UPDATE users SET lastlogin= NOW(), logincount=logincount + 1 WHERE login='$username'";
$Update = mysql_query($UpdateRecords);
}
The index part
Code: Select all
echo '<form action="'.$resultpage.'" method="post" target="1">';
echo '<b>Usario:</b><br><input maxLength=40 size=15 name=username><br><b>Clave:</b><br><input type=password maxLength=25 size=15 name=password><br>';
echo "<button name="submit" type="submit" style="font-family: v; font-size: 10pt; color: #5E6A7B; border: 1px solid #5E6A7B; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1">Login</button>";
echo '</form>';
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 10:33 am
installed Firefox, now the cookies are being set, however for some dumb reason i just cant retrieve them.
Is there something, i might have forgotten.??
Last edited by
ol4pr0 on Mon Jun 21, 2004 10:50 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 21, 2004 10:35 am
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 12:26 pm
I am clueless
output
Array ( [PHPSESSID] => b9bc4db24acfcad40c476154e834d5c4 )
While the cookie manager in Firefox clearly states that
localhost USERNAME
localhost PASSWORD
is set.
The popup box tells me the same.
refresh as many as you want but the output is the same.
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Mon Jun 21, 2004 12:31 pm
set a time frame for the cookie
setcookie("blah", $var, time() + 3600);
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 2:01 pm
i will try that..
however i tried the following
on my very index page.
return
Array ( [USERNAME] => SOMEUSERNAME [PHPSESSID] => a51050a9f76c64dc27046d5770d4fb78 )
Even tho that the firefox did gave the popup to modify the cookie with the username logged in.
name: Username
content: ik
path :/inc/
secure server: no
.....
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jun 21, 2004 2:14 pm
Guess the path was the boo boo
Code: Select all
setcookie("USERNAME", $_POST['username'],time()+3600,"/");
That fixed it..