cookies setup

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

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

btw, the cookie will never get set if you are trying to set it for a different domain that where the cookie is being sent from..
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

Hi ,

Parse Error?

In few browsers , i didn't get problem with cookies.....

Please try in your system.... Please click once http://www.searchchips.com

username : catherine
password:catherine

afterthat please close the browser .... It shuoldn't ask the username and password..
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

can i set this one,
setcookie ("member_id", "$id", time()+3600000,"/","searchchips.com");
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

Hi,
i tried same domain only.. getting problem like this....
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

Hi ,

I changed like this :::
setcookie ("member_id", "$id", time()+3600000,"/","lotofcontent.com");

My website is http://www.lotofcontent.com/searchchipsnew/

Still getting problem
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe $id is empty?
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

Hi,
I observed onething ... i.e $id is fine.....

i echo $id before the setcookie()..... it's printing without errors....
As of my knowledge, it we use echo before setcookie() , it should give error .like Header is added by.....

I am not getting any error......like this

Simply it prints the value.
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

http://www.lotsofcontent.com/searchchipsnew/test.php

just you will observe this one..... just see :HTTP_COOKIE value
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

searchchips.com:

Code: Select all

HTTP/1.1 200 OK
Date: Fri, 20 Aug 2004 07:48:56 GMT
Server: Apache/1.3.31 (Unix) mod_pointer/0.8 PHP/4.3.2
X-Powered-By: PHP/4.3.2
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
lotsofcontent.com/searchchipsnew/index.php:

Code: Select all

HTTP/1.1 200 OK
Date: Fri, 20 Aug 2004 07:49:49 GMT
Server: Apache/1.3.31 (Unix) FrontPage/5.0.2.2634
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Set-Cookie: PHPSESSID=3cf0a304db0e3e1e421b7129f0bb075d; path=/
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
only a session cookie is set on your main page.

you have some form of errors in your setcookie call..
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Setting the cookies always worked fine. But if you've used sessions you'll find that when removing the cookie (logging out etc) the session id still remains in the cookie even after session_destroy(). session_destroy() doesn't remove the session id from the cookie. When removing sessions also do setcookie(session_name(),"",0,"/");
http://www.php.net/manual/en/function.s ... estroy.php
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

Hi ,

I am using sessions and cookies in my site .... can i use both ?

setcookie ("member_id", "$id", time()+36000000,"/","$HTTP_HOST");
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're still not setting a cookie.. post all your code please.
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi ,
Here i am posting my code....please review once..

Code: Select all

<?
session_start();

//**************************************************************

//					Main page --- This is base-one of all operations

//**************************************************************
//app.php file consists ------  Database connection and all variables.   
	include("lib/app.php");
//include all class files

include("classes/member.class.php");
include("classes/Memberchips.class.php");
include("classes/searchchips_codes.class.php");
include("classes/searchchips_membercodes.class.php");
switch($action){
	case 'login':
		$objmember->loadMultiple("member_name='$member_name' and password='$password'");
		if(count($objmember->searchResults)){
			$id=$objmember->searchResults[0]['member_id'];
			setcookie ("member_id", "$id", time()+36000000,"/","$HTTP_HOST");
			$first_name=$objmember->searchResults[0]['first_name'];
			$last_name=$objmember->searchResults[0]['last_name'];
			$chips=$objmember->loadchips($id);
			$back_id=$id;
			$objmemberchips->loadMultiple("member_id=".$id ." and type_chips='home-page'");
			$_SESSION['home_page']=$objmemberchips->searchResults[0]['chips'];
			$objmemberchips->searchResults[0]['chips']="";
			$objmemberchips->loadMultiple("member_id=".$id." and type_chips='book-page'");
			$_SESSION['book_homepage']=$objmemberchips->searchResults[1]['chips'];
			$packid=1;
			include("member-home.php");
		}
		else{
			$msg="Invalid Username/Password !!";
			include("home.php");
		}
	break;
	default:
		if($_COOKIE["member_id"]){
			$res=$objmember->loadSingle($_COOKIE["member_id"]);
			$first_name=$res['first_name'];
			$last_name=$res['last_name'];
			$chips=$objmember->loadchips($_COOKIE["member_id"]);
			checklinks();
			include("member-home.php");
		}	
		else{ 
				include("home.php");
		}
	break;

}

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

Hi ,

I wrote sample file for cookie testing ....It's working fine.......http://www.lotsofcontent.com/searchchipsnew/sample.php



But In my site it is not working ....http://www.lotsofcontent.com/searchchipsnew/


So problem in my file only...........

Thanks,
Krishna
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code is set up for register globals being on, each page, however, it doesn't appear register globals is on with that server (which it shouldn't be on)
Post Reply