...

View Full Version : Session's working but cookies won't store



SilentChamber
09-01-2006, 03:19 PM
Hello,

Here's my problem,

I'm working on my gallery script and my cookies don't seem to work, I am not sure if it has anything to do with the fact that i'm using mod_rewrite or not.

i've used this code on several sites of mine and they all work fine. my friend recommended to make an OOP version of it, but i'm not so sure how to i know basic OOP but not enought to make anythign with it.. anyway here's my code.


login.php


<?php
if($remember == "on") {
$cookiedata = $r->username.'-'.$r->password;
setcookie("******-*****", $cookiedata, time()+31536000);
}
?>


header.php


<?php
if(isset($_COOKIE['******-*****'])){
$cookiedata = explode("-", $_COOKIE['******-*****']);
$cookie_user = $cookiedata[0];
$cookie_pass = $cookiedata[1];
$query_user = "SELECT * FROM `users` WHERE `username` = '$cookie_user' AND `password` = '$cookie_pass'";
$exec_user = mysql_query($query_user) or die(mysql_error());
if(mysql_num_rows($exec_user) == 0) {
header('location: http://www.silentchamber.co.uk/index/');
require('inc/footer.php');
exit;
}
else {
while($r_user=mysql_fetch_object($exec_user)){
$userid = $r_user->id;
$username = $r_user->username;
$userdisplay = $r_user->displayname;
$access = $r_user->access;
}
session_register('******-*****');

$_SESSION['username'] = $username;
$_SESSION['displayname'] = $userdisplay;
$_SESSION['userid'] = $userid;
$_SESSION['useraccess'] = $access;

}
}
?>



reason why i think it is the mod rewrite causing the problem because i've noticed that in the dir with header.php it works but header is included into the index.php file..


hope someone can help me with this.


Regards,



Neil Hickman

Company Director, SilentChamber Photography <silentchamber.co.uk>

Fumigator
09-01-2006, 05:19 PM
my cookies don't seem to work

Way too vague to be any help.

SilentChamber
09-01-2006, 07:10 PM
Way too vague to be any help.


What i mean by that is the cookie isn't set at all, i have cookie editors and none of them can find that cookie anywhere even after the script is run.

Lee Stevens
09-01-2006, 11:49 PM
havnt set the path:


setcookie("******-*****", $cookiedata, time()+31536000, '/');

SilentChamber
09-02-2006, 01:20 PM
ok i've set the path, and it still doesn't create the cookie, theres no trace of it anywhere

Lee Stevens
09-02-2006, 11:40 PM
Ok can you explain this for me.


$cookiedata = $r->username.'-'.$r->password;
setcookie("******-*****", $cookiedata, time()+31536000);


if '$cookiedata' is there username and password, whats the session name?

SilentChamber
09-03-2006, 01:16 AM
Ok can you explain this for me.


$cookiedata = $r->username.'-'.$r->password;
setcookie("******-*****", $cookiedata, time()+31536000);


if '$cookiedata' is there username and password, whats the session name?

the session name is the same as the cookie name... all RCBLOG-LOGIN

Lee Stevens
09-03-2006, 09:03 AM
So is it actuly set to that in your scripts not *******-*******

SilentChamber
09-03-2006, 12:35 PM
So is it actuly set to that in your scripts not *******-*******

yes it is..

Lee Stevens
09-03-2006, 11:19 PM
setcookie("RCBLOGLOGIN", $cookiedata, time()+31536000, '/');


Try it whith out the '-' amd see if it works.... thats the only thing i can think of inless your useing it in a function or something....

Edit:


<?php
if($remember == "on") {
$cookiedata = $r->username.'-'.$r->password;
setcookie("******-*****", $cookiedata, time()+31536000, '/');
}
?>


$r->username & $r->password arnt in the IF statment so it probley wont no what the values are, try:



<?php
if($remember == "on") {
$cookiedata = $_POST['username'].'-'.$_POST['password'];
setcookie("******-*****", $cookiedata, time()+31536000, '/');
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum