Advertisements

having trouble with cookie coding

Postby mezz » Sat Jul 14, 2007 11:48 am

Offline
mezz
Posts: 6
Joined: Sat Jul 14, 2007 11:39 am
Ok, mezz here just new and having so much trouble with this coding. I imagine the mistake I'm making is small but I just can't work it out.

I'm a newbie at this so any answers will need to be in baby speak.

What I want:
I want to track a surfer's ID number through my site. They click on a google ad that has an ID in it and come to my page. While on my page, instead of immediately clicking on the offer, they see an article they can read to find more information before they buy and click on the link. I want their ID number to follow them to the article and then back again so that when they do click on my offer I know which ad they arrived from in the first place.

this is where I am.

have this cookie code in the header of my page above <html>

<?php
setcookie($cookie['kid']);
?>

the id is on that page I arrive at.

then in the <body> section I have this:

<?php

if( isset($cookie['kid']) ) {
$sub_id = $cookie['kid'];
}

?>

but when I click on a link the ID doesn't go through. What am I doing wrong?

I do hope I can find someone who can help. I've been trying to find the answer for months. I'm going a little spare :shock:

mezz

Postby tutorialspoint » Sat Jul 14, 2007 9:40 pm

Offline
tutorialspoint
Site Admin
Posts: 143
Joined: Fri Apr 27, 2007 6:52 pm
Hi Mezz..Try the following

To set a cookie

<?php

setcookie( "Cookie_name", "Cookie_Value" );
?>

Now you can access about cookie as follows:

<?php

$value = $_COOKIE( "Cookie_name" );
if( isset( $value ) )
{
do whatever you like.....
}
?>


Hope this helps.....
Moderator, TP
Keep visiting and share this site with your friends.

Postby mezz » Mon Jul 16, 2007 1:50 pm

Offline
mezz
Posts: 6
Joined: Sat Jul 14, 2007 11:39 am
so is 'kid' my value or my name? I'm thinking it's my name. And if it is, what's my value? Is sub_id the value?

mezz

Postby tutorialspoint » Mon Jul 16, 2007 6:24 pm

Offline
tutorialspoint
Site Admin
Posts: 143
Joined: Fri Apr 27, 2007 6:52 pm
Hi Mezz!

I would suggest you to through COOKIES session available on http://www.tutorialspoint.com/php/php_cookies.htm

Your Cookies concepts need more burshup. So please go through this tutorial to understand basics of PHP cookies.


Still you would have question then I will help you.

Thanks
Moderator, TP
Keep visiting and share this site with your friends.

Postby mezz » Sat Jul 21, 2007 4:24 am

Offline
mezz
Posts: 6
Joined: Sat Jul 14, 2007 11:39 am
Ok so this is what I did.

I put:

<?php
setcookie( "Cookie_['sub_id']", "Cookie_['kid']" );
?>

in the header

and I put:

<?php
$value = ( "Cookie_['sub_id']" );
if( isset( $kid ) );
{
$sub_id = $cookie['kid'];
}

?>

in the body.

At first I put $value = $COOKIE( "Cookie_['sub_id']") as the first line but I kept getting an error message about unsupported () in that line.

In the URL address line it is still not showing the subID number going across and if it's working it should right?

need more help

(oh and just for some hopefully helpful feedback. Your tute page that I read may make sense to someone who knows what you're talking about but for a greenie like me, I'm still confused. )

mezz

Postby mezz » Tue Jul 24, 2007 10:22 am

Offline
mezz
Posts: 6
Joined: Sat Jul 14, 2007 11:39 am
No comments at all????? :(

Postby tutorialspoint » Tue Jul 24, 2007 10:03 pm

Offline
tutorialspoint
Site Admin
Posts: 143
Joined: Fri Apr 27, 2007 6:52 pm
Hi Mezz!

Believe me its not too difficult subject to understand. Its very simple.

Assume you want to save a user ID ( foo ) on one page and you want to access this user ID on any other page. Then here is example


Put this code to set cookie

<?php
setcookie( "USER_ID", "foo" );
?>


Now you can access this cookie on any PHP page as follows:

<?php

$value = $_COOKIE( "USER_ID" );
if( isset( $value ) )
{
echo "User ID is ". $value;
}else{
echo "User ID is not set";
}
?>

Please tell me what you are not getting here.

Mohit.
Moderator, TP
Keep visiting and share this site with your friends.

Postby mezz » Thu Aug 02, 2007 12:54 pm

Offline
mezz
Posts: 6
Joined: Sat Jul 14, 2007 11:39 am
Ok, here's what I've done.....

I copied your setcookie thing

<?php
setcookie( "USER_ID", "foo" );
?>

and changed it to

<?php
setcookie( "USER_ID", "kid" );
?>

saved the page and then went to see if it worked. Everything ok so far.

I then put the next bit in....


<?php

$value = $_COOKIE( "USER_ID" );
if( isset( $value ) )
{
echo "User ID is ". $value;
}else{
echo "User ID is not set";
}
?>


Fatal error: Call to undefined function: array() which is the ( "USER_ID" ) brackets.

So then I removed the brackets and got this message Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

So then I changed it to this

<?php

$value = ($_COOKIE [ "USER_ID" ]);
if( isset( $value ) )
{
echo "User ID is ". $value;
}else{
echo "User ID is not set";
}
?>

Now after saving I go to my page and check it out and just above the page it says "USERID is Kid"

Well, I don't want that up there. I don't think it's supposed to be up there is it?

So anyway, I did a whole heap of other stuff too that I won't get into now coz it'll just be confusing. What do you suggest I do?

mezz

Postby tutorialspoint » Thu Aug 02, 2007 3:39 pm

Offline
tutorialspoint
Site Admin
Posts: 143
Joined: Fri Apr 27, 2007 6:52 pm
Hi Mezz,

What I understand from your description is that now you are able to set a cookie and you are able access this cookie in another page also.

But I did not understand your sentence when you said it should not be up there...why it should not be up there...once you set a cookie it will remain up till it expired.

Second from your original problem you said you want to track your site visitors who are coming from google ads. So if that is the case then set your cookie in a page where your visitors are landing and then access that cookie in a page where you are taking orders.

Does it help ?

I'm sorry if I'm not understanding your requirement.
Moderator, TP
Keep visiting and share this site with your friends.

Postby mezz » Sat Aug 04, 2007 3:22 am

Offline
mezz
Posts: 6
Joined: Sat Jul 14, 2007 11:39 am
Here is the link to my page.

http://greatthisisit.com/seekingpartner ... ?sub=$kid/

Just above the header it says 'User ID is not set'

When I said that I don't want to see that, I meant that I don't see it on any other site I visit that has cookies so why can I see it on mine?

And if the cookies are working why are they still not being recorded at the affiliate network when other pages are?

mezz

Postby tutorialspoint » Sat Aug 04, 2007 5:28 am

Offline
tutorialspoint
Site Admin
Posts: 143
Joined: Fri Apr 27, 2007 6:52 pm
Hi Mezz!

Its being displayed at the top of your page because you have echoed it using "echo" function. Just remove this function and you won't get it on your page.

Regarding why it is not being recorded, I don't see source code to record it thats why it is not being recorded. You have to write logic to record it. Now I don't know where do you want to record it. So just check what are you doing for other pages, and then do same for this page as well;



Thanks
Moderator, TP
Keep visiting and share this site with your friends.

»

Postby justinbellaa03 » Fri Dec 28, 2012 4:36 am

Offline
justinbellaa03
Posts: 1
Joined: Fri Dec 28, 2012 4:22 am
Location: INDIA
Hello,
I have visited this php script forum. I am also beginner in php.so, that's forum is very beneficial for me and it gives me lots of information that will be very useful to me in the future.I have read this question but i am note able to give your answer right now,sorry for that.So i am giving you this expert link for your queries.
thanks.
----------------------
[url=http://www.ezdia.com/epad/ati-radeon-hd-5670-series-graphics-card-amd/6972/] ATI RADEON HD 5670 – SERIES GRAPHICS CARDS FROM AMD [/url]