24, July 2008

Cookie not being set - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  Php User Class
Topic: Cookie not being set
« previous next »
Pages: [1] Print

Author Topic: Cookie not being set  (Read 608 times)
Just another rainy day
*
Posts: 1
10 credits
Members referred : 0


« on: Dec 31, 2007, 06:10:14 PM »

Using php 5.14, phpuser v 0.91

Stuff that works:
  registration
  email activation

I can't get the cookies to save, and the $_SESSION var is not being set.

If the user logs in with appropriate user/password, I redirect to another page, but the phpuser class constructor does not pickup the session var ("userSessionValue") nor an appropriate cookie on the user's machine.

What should I look for?

Essentially, I'm doing this:

in all php files on the site, I have

Code:
require "mytemplatefile.php";

Inside "mytemplatefile.php", I have this:

Code:
require "access.class.php";

Inside "access.class.php", I have the following:

Code:
class flexibleAccess
{
      ... the class code
}

$userX = new flexibleAccess();

The act of logging in is handled like so:

Code:
if (isset($_POST['username']))      { trim(strip_tags(stripslashes($_POST['username'])));      }
if (isset($_POST['password']))      { trim(strip_tags(stripslashes($_POST['password'])));      }

if ((!empty($_POST['username'])) && (!empty($_POST['password'])))
{
if ($userX->login($_POST['username'], $_POST['password'], true, true))
{
// redirect to the home page
  header("Location: http://blahblah/index.php");
  }
  else
  {
$htmlStr .= "Invalid login attempt.";
  }
}
else
{
$htmlStr .= "You must specify a user ID and password.";
}

The problem is that when I get to the redirected page, the expected session var and cookie don't appear to exist.
« Last Edit: Dec 31, 2007, 07:47:22 PM by jsimmons »
I crack Photoshop!
*
Gender: Male
Posts: 3
22 credits
Members referred : 0


« Reply #1 on: Jun 05, 2008, 12:51:40 AM »

Hi, I'm having this same problem.
When I login and am redirected to my test page, the output is simply
NULL
NULL
(simple var_dumps, see the code below).

Any idea why this isn't working? I love the idea of this nice lightweight & flexible user class. I'll love the class itself as soon as i get this working!

cheers,
Kris


PHPUserClass v0.93
PHP 5.2.5 (OS X Leopard default install)


Here is my login page (only slightly modified from example1.php)
Code:
<?php
<?
/*
Basic login example with php user class
http://phpUserClass.com
*/
require_once 'access.config.php';
require_once 
'access.class.php';

$user = new flexibleAccess(''$settings);

if ( 
$_GET['logout'] == ) {
$user->logout('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
}

if ( !
$user->is_loaded() ) {

// Login stuff:
if ( isset($_POST['uname']) && isset($_POST['pwd'])) {
if ( !$user->login($_POST['uname'],$_POST['pwd'],$_POST['remember'] ) ) {
echo 'Wrong username and/or password';
} else {
// User is now loaded
//header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
header('Location: test.php');
}
}

echo '<h1>Login</h1>
<p><form method="post" action="'
.$_SERVER['PHP_SELF'].'" />
username: <input type="text" name="uname" /><br /><br />
password: <input type="password" name="pwd" /><br /><br />
Remember me? <input type="checkbox" name="remember" value="1" /><br /><br />
<input type="submit" value="login" />
</form>
</p>'
;
} else {
// User is loaded
echo '<a href="'.$_SERVER['PHP_SELF'].'?logout=1">logout</a>';
}
?>

?>

And my test page where I'm checking to see if any session or cookie vars are being set:
Code:
<?php
echo var_dump($_SERVER['session']);
echo 
'<br>';
echo 
var_dump($_SERVER['cookie']);
?>

I crack Photoshop!
*
Gender: Male
Posts: 3
22 credits
Members referred : 0


« Reply #2 on: Jun 06, 2008, 06:51:21 AM »

Well, it turned my issue was not just one problem. It was a bit of a comedy of errors in there on my part. In my troubleshooting though, I do believe I've come across a couple of legitimate bugs in v0.93. I'll put these & my suggestions in a separate post to make sure they get noticed. Hopefully they'll help someone else out, too.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7491
Tags : session var Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  Php User Class
Topic: Cookie not being set
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 24, 2008, 02:52:34 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.712
Total Topics: 7.376
Total Members: 3.708
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: ravindra_20

48 Guests, 4 Users online :

8 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.