Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thread moved to the Dreamweaver Application Development forum, which deals with PHP and other server-side languages.
If you're storing login information in cookies, save the username in a cookie and just echo the value:
<?php
if (isset($_COOKIE['ID_my_site'])) {
echo 'Hello, ' . $_COOKIE['ID_my_site'];
}
?>
Adding code as an attachment makes life more difficult for others to help you. They have to download it, scan it for viruses, unzip it, and then open it. Many people won't bother. Post code directly in your message. Instructions on how to do so here: http://forums.adobe.com/thread/427712.
Copy link to clipboard
Copied
ok. so here is the coding that i am using to store the username. it's very basic, but it works...
// JavaScript Document
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// - - - - - - - - End of Public Domain Cookie Code - - - - - - - -
// - - - - - - - - JTotW Cookie Functions by Nick Heinle- - - - - - - -
function show_count() {
var expdate = new Date();
var num;
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
if(!(num = GetCookie("jtotwcount")))
num = 0;
num++;
SetCookie ("jtotwcount", num, expdate);
if (num == 1) document.write("Since this is the first time you have been here, please take a moment to look around.");
else document.write("You have been here " + num + " times.");
}
function auto_show_name() {
if(GetCookie("jtotwname") != null)
document.write("Welcome back to this week\'s tip " + GetCookie('jtotwname') + ". ");
else {
document.write("<FORM>Please enter your name: <INPUT TYPE = \"text\" NAME = \"nameinput\">" + "<BR><BR><INPUT TYPE = \"button\" VALUE = \"Save to Cookie\" onClick = \"set_name(this.form)\"></FORM>");
document.write("Please enter your first name in the input" + " box and press the \"Save to Cookie\" button, then the page will automatically reload. ");
}
}
function set_name(form) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
var username = form.nameinput.value
if (username != "") {
if (confirm("Are you sure you want this saved as your name?")) {
SetCookie ("jtotwname", username, expdate);
window.history.go(0);
}
} else alert("Geez, at least enter something, entering nothing will cause an error.");
}
so i tried doing the following; <?php
if (isset($_COOKIE['jtotwname'])) {
echo 'Hello, ' . $_COOKIE['jtotwname'];
}
?>, but it did not work... any ideas?
and why would they have the 'attach files' feature if it is difficult?
Copy link to clipboard
Copied
future-architect wrote:
but it did not work... any ideas?
From that jumble of code, it's impossible to tell how or where the code is being used. You start with a JavaScript document, but it looks as though a large part of the code is intended to be inside a web page. Otherwise, document.write wouldn't work.
For PHP to be able to display the value of a cookie, the cookie must have already been created. It won't display on the same page at the time of creation. The page needs to be reloaded for the cookie to be readable.
Since you're using PHP, it would probably be a lot easier to use PHP's setcookie() function to create the cookie. Take a look at the PHP manual to see how it works: http://docs.php.net/manual/en/function.setcookie.php.
and why would they have the 'attach files' feature if it is difficult?
It's intended for large files, such as FLA files used in Flash. For short bits of code, it's much more convenient to insert the code directly in the post. Everybody who provides help here does so on a voluntary basis. Making it easier for others increases the likelihood of getting an answer to your questions.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now