Odd dots in cookies
Moderator: General Moderators
Odd dots in cookies
Hello to the forums! This is my first post here and I'm rather confused about something regarding cookies.
I'm just learning how to use them and they seem to be the best choice to transfer data between two PHP
pages. I've gotten the initial transfer working with "testone.php" setting up a cookie and defining a username
variable. "testtwo.php" reads the cookie, and outputs it as a echo - the output is this:
This is a test, your username .TEONNYN. should be all caps.
I can't figure out where those two dots are coming from, or how to get rid of them.
This is the output from testone.php: Your username on this page is Teonnyn
- no dots. Does anyone have any advice on removing those two dots, or on better methods of passing variables without using forms?
I'm just learning how to use them and they seem to be the best choice to transfer data between two PHP
pages. I've gotten the initial transfer working with "testone.php" setting up a cookie and defining a username
variable. "testtwo.php" reads the cookie, and outputs it as a echo - the output is this:
This is a test, your username .TEONNYN. should be all caps.
I can't figure out where those two dots are coming from, or how to get rid of them.
This is the output from testone.php: Your username on this page is Teonnyn
- no dots. Does anyone have any advice on removing those two dots, or on better methods of passing variables without using forms?
Re: Odd dots in cookies
What's the code you have?
Re: Odd dots in cookies
testone.php
testtwo.php
The whole "upper" thing was just a test to see if I could manipulate the string. The if statement was added in to see if I could catch where the dots were being added, so far it seems to be somewhere in the transfer.
Code: Select all
<?php
$uservar = "Teonnyn";
echo "Your username on this page is $uservar";
setcookie("user","$uservar");
?>Code: Select all
<?php
$test = ($_COOKIE["user"]);
$upper = strtoupper($test);
echo "This is a test, your username $upper should be all caps.";
if (($_COOKIE["user"]) == "Teonnyn") {
echo "Great! Your name is Teonnyn!";
}
?>Re: Odd dots in cookies
I tried playing around with sessions but never got the examples working on two different pages like the cookies seem to be - material used: Beginning PHP 5 and mySQL, and w3Schools. My overall goal is to develop a small script that'll transfer a username from Joomla into a Flash-based program to check if the user is logged in.
Re: Odd dots in cookies
Just a fun thing to check:
Change $uservar in testone.php to something else and see what happens.
Change $uservar in testone.php to something else and see what happens.
Re: Odd dots in cookies
The actual variable or the name itself?
Re: Odd dots in cookies
The contents. Like, change the username to something that's not "Teonnyn".Teonnyn wrote:The actual variable or the name itself?
Re: Odd dots in cookies
Interesting.. I changed it to "Extratest" and removed the upper and if code. Testone now outputs "Your username on this page is Extratest", while TestTwo doesn't seem to be getting it at all - "This is a test, your username should be ."
testtwo.php
testtwo.php
Code: Select all
<?php
$test = ($_COOKIE["user"]);
echo "This is a test, your username should be .$test.";
?>Re: Odd dots in cookies
Is there a really good tutorial on using sessions? I haven't managed to find one yet and my book only explains the various parts, but doesn't go in depth on how to use them. Plus - the one thing I really need to know about sessions is this: Can they be used between two completely independent scripts on the same server as long as they both reference the same session? Independent meaning no form or html hyperlink between pages.
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: Odd dots in cookies
You don't need the dots surrounding the variable when used in that context. You only use dots outside of quote marks (see below) - anything inside quotes in an echo statement will be printed.Teonnyn wrote:Interesting.. I changed it to "Extratest" and removed the upper and if code. Testone now outputs "Your username on this page is Extratest", while TestTwo doesn't seem to be getting it at all - "This is a test, your username should be ."
testtwo.phpCode: Select all
<?php $test = ($_COOKIE["user"]); echo "This is a test, your username should be .$test."; ?>
Code: Select all
$variable = "string":
echo "This is a sample concatenation " . $variable . " in this space";
// outputs 'This is a sample concatenation string in this space'
// equivalent to
echo "This is a sample concatenation $variable in this space";
file1.php
Code: Select all
session_start();
$_SESSION['yourName'] == "Matt";
Code: Select all
session_start();
$name = $_SESSION['yourName'];
echo "Hello, $name";
Re: Odd dots in cookies
Do'oh! That would explain why I had no luck getting sessions to work. I thought only one session start was needed. Anyway, thank you all! Thus far this has been one of the most responsive forums I've been in ever. 
Re: Odd dots in cookies
session_start() is confusingly named. That's what got me the first time.