Forum Moderators: coopster

Message Too Old, No Replies

Have cookie... need to post

         

Acternaweb

7:32 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



Thanks to several folks here I now have a working cookie script. Now how do I show the value of the cookie on a secondary page?

For example on the home page the user puts their name, on next page I want to say hello username.

kazecoder

8:06 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



You could url encode the name in the link to page 2:

page2.php?name=bob

or

you can access the cookie through a variable:

$HTTP_COOKIE_VARS[cookie_name]

Acternaweb

8:25 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



Forgive the naivety, but what where the
$HTTP_COOKIE_VARS[cookie_name]
Go?
<?php
$HTTP_COOKIE_VARS[cookie_name]
?>

jatar_k

8:36 pm on Apr 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if your version is greater than 4.1.0 then you should use $_COOKIE

so wherever you want their name to show put
echo $_COOKIE['cookie_name'];

Acternaweb

8:41 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



Dumb question but does the page have to be a php page or can I keep it html?

jatar_k

8:46 pm on Apr 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if your html pages are parsed for php then either will work, otherwise you need a php extension.

<added>there are no dumb questions

Acternaweb

10:32 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



HI

I tried using the code on both a .html and .php page but neither works.

Any more ideas?

jatar_k

11:07 pm on Apr 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this then to see what the proper name of the var would be

echo '<pre>';
print_r($_COOKIE);
echo '</pre>';

that will output all of the cookie varnames and values

Acternaweb

12:38 pm on May 2, 2005 (gmt 0)

10+ Year Member



Nothing is working. I have posted my code, any help would be much appreciated. I am at a lost as to what I am doing wrong.

#!/usr/local/bin/php --
<?php
session_start();
if (!empty($_SESSION['your_name'])) //check to see if $_SESSION['your_name'] contains anything

{

echo "I already know your name, " . $_SESSION['your_name'];

}

else {

if (empty($_POST['submit'])) {

echo "<form name=myform method=post action=$PHP_SELF>

<input type=text name=first_name>first name<BR>

<input type=submit name=submit value=submit>

</form>";

}

else {

$_SESSION['your_name'] = $_POST['first_name'];

echo "Thank you, {$_SESSION ['your_name']}";

}

} ?>

<P>

jatar_k

7:32 pm on May 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ah, you said cookie in your first post so we were talking about cookies but you meant session, try this then

echo '<pre>';
print_r($_SESSION);
echo '</pre>';

that will show you everything in the session, maybe slap it in right after the session_start