Jump to content

Cookie reading problem...


clonetrooper9494

Recommended Posts

I have a page that get's included on a whole bunch of pages. It saysif(strlen($_COOKIE['username']) < 2){$stuff = "</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net/login/index.phtml'\">Login";}else{$stuff = "</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net/login/logout.php'\">Logout";}then echos logout, or login. at this page http://clone-drone.net/login/ if you login as u=test and p=test , and then go back to the login page again, the Login button disapears, and when you right click there, the menu says Login even if you logout: http://clone-drone.net/login/logout.php... it stays there no matter what!this is the code that hides the Login button:if(strlen($_COOKIE['username']) < 2){echo '<input type="submit" name="submit" value="Login">';}does any one see why this is happening?

Link to comment
Share on other sites

Well, I guess I could change it so it tested if it was empty... how would I do that?I don't think that the rest of the code is the problem... I just don't really...here is the code of the menu:

<?php$extra = $_GET['extra'];$link = $_GET['link'];$login = $_COOKIE['user'];if(strlen($_COOKIE['username']) < 2){$stuff = "</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net/login/index.phtml'\">Login";}else{$stuff = "</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net/login/logout.php'\">Logout";}echo "<script type=\"text/javascript\">var x = '0';var y = '0';function show_coords(e){	e = (e) ? e : window.event;	x = e.clientX;	y = e.clientY;}document.onmousemove = show_coords;function movemenu(){document.getElementById('menu').style.left = x + 'px';document.getElementById('menu').style.top = y + 'px';return false}function movemenuback(){document.getElementById('menu').style.left = '-100px';document.getElementById('menu').style.top = '-100px';return false}</script><body oncontextmenu=\"return movemenu()\" onclick='movemenuback()'><div id=\"menu\" style=\"position:absolute;top:-100;left:-100;display:block;\"><table border='1' bgcolor='EEEEEE' bordercolor='BBBBBB' style=\"border-collapse: collapse;\"><tr><td><table border='0' bgcolor='EEEEEE' bordercolor='BBBBBB'><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net'\">Home</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net'\">Games$stuff//this is where the is put</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://cmail.clone-drone.net'\">Clone-Mail<textarea style=\"display:none\" id=\"addon\"></tr></td><tr><td><hr width=\"90%\"></td></tr><tr></textarea><textarea style=\"display:none\" id=\"extra\">$extra</textarea><script type=\"text/javascript\">var t = document.getElementById('extra').value;var p = document.getElementById('addon').value;if(t == ''){document.write('')}else{document.write(p + '</td><tr><td onmouseover=\"this.style.backgroundColor = \'#BBBBBB\'\" onmouseout=\"this.style.backgroundColor = \'#EEEEEE\'\" style=\'background-color:EEEEEE;\' onclick=\" window.location=\'$link\'\">' + t + '</td>')}</script></tr></td></table></tr></td></table></div>";?>

and this is the code of the login page:

<?phpinclude("http://clone-drone.net/php_scripts/navigate.php?extra=&link=");?><html><head><title>Clone-Drone.net - Login</title><script>function check_username(){u = document.getElementById('username').value;if(u == 'Username'){document.getElementById('username').value = '';}}function check_password(){document.getElementById('password_div').innerHTML = '<input type="password" name="pass">';}</script></head><body bgcolor="#FFFFFF"><form action="/login/login.php" method="post"><input type="text" name="user" value="Username" onclick="check_username()" id="username"><br><div id="password_div"><input type="text" name="pass" value="Password" onclick="check_password()"></div><br><?phpif(strlen($_COOKIE['username']) < 2){echo '<input type="submit" name="submit" value="Login">';}?></form></body></html>

Link to comment
Share on other sites

You could do this:

if (isset($_COOKIE['username']) && $_COOKIE['username'] != "")

You'll also want to validate the username that is in the cookie. It's easy for someone to just make their own cookie and have it be sent to the server, so you'll need to check that the information inside the cookie is accurate. You might also want to include a hashed password in the cookie and make sure that the username and password match what is in the database. I'm not sure about the other problem you're having, I tried logging in to the page you linked to but I didn't see any type of menu or anything. The structure of your pages is a little messed up though. View the HTML source of your login page, it starts with a bunch of Javascript, then it has a body tag with some divs and tables and a couple textareas, then it has the <html> tag and the head and another body. You'll want to do something about that, get the document structured correctly first.

Link to comment
Share on other sites

I'm not sure about the other problem you're having, I tried logging in to the page you linked to but I didn't see any type of menu or anything. The structure of your pages is a little messed up though. View the HTML source of your login page, it starts with a bunch of Javascript, then it has a body tag with some divs and tables and a couple textareas, then it has the <html> tag and the head and another body. You'll want to do something about that, get the document structured correctly first.
That is my host... it adds thouse one by itself... to make sure that iframes are not copying my site somehow... or something like that...(also, try right click button on your mouse... then a menu pops up. not sure if you you missed that or something)But that still didn't solve my problem... the only thing I change in my menu code is this:
if(isset($_COOKIE['username']) && $_COOKIE['username'] != ""){$stuff = "</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net/login/logout.php'\">Logout";}else{$stuff = "</tr></td><tr><td onmouseover=\"this.style.backgroundColor = '#BBBBBB'\" onmouseout=\"this.style.backgroundColor = '#EEEEEE'\" style='background-color:EEEEEE;' onclick=\" window.location='http://clone-drone.net/login/index.phtml'\">Login";}

didn't touch anything else.I also fixed it so that the menu is in the body tags... but I cannot control the JavaScripts before the HTML tags...

Link to comment
Share on other sites

That is my host... it adds thouse one by itself... to make sure that iframes are not copying my site somehow... or something like that...
Really? It looks like the include statement you had before the <html> tag.
also, try right click button on your mouse... then a menu pops up. not sure if you you missed that or something
Ahh. I did miss that, I have my browser configured to hide right-clicks from Javascript. So the issue is that the popup menu has the wrong link in it? Do a print_r on the $_COOKIE array, what is in there?
I also fixed it so that the menu is in the body tags... but I cannot control the JavaScripts before the HTML tags...
It's better, but you still have 2 body tags.
Link to comment
Share on other sites

huh. that is strange. it seems that if I try to read the cookie in the menu page, it just can't see it. the login page: http://clone-drone.net/login/ with the username and password as 'test' , I have the include and the real login page try and print the cookie, and only the /login/ page works... the navigate page doesn't even print it if you view it with out the include ( http://www.clone-drone.net/php_scripts/navigate.php )... it seems that that page can't read it. I don't know why this is happening... can any one else figure this out why it's happening?I got rid of the 2 body tags, but now some Java Script is not in any body or head tags! I'll work on that later...

Link to comment
Share on other sites

huh. that is strange. it seems that if I try to read the cookie in the menu page, it just can't see it. the login page
As these pages are in different folders, then depending on how your site is defined, I wonder if you're navigating beyond the scope of the cookie by going to another domain/subdomain etc. Try putting both files in the same folder.
Link to comment
Share on other sites

I would bet 10 to 1 that it is because you are including the file using http. When you do that, the web server sends a request (to itself) for the file. When it sends that request, the cookie that the client sent is not included in the server's request.Include the page normally instead of over http and it should work.

Link to comment
Share on other sites

I will change the folderIf I try to say include("clone-drone.net/php_scripts/navigate.php?extra=&link="); it says that /clone-drone.net/php_scripts/navigate.php?extra=&link= doesn't exsist...ok, I moved the nviagte script into the folder that sets the cookies... and it still doesn't work!I have a different way.. I am already sending info through $_GET... so I could send the username pf the cookie through there to when I get the navigate page through include() ...

Link to comment
Share on other sites

That's not the right path to use, don't use your domain name. You're not trying to communicate with a web server, you're trying to access the filesystem. Print the constant __FILE__ to see what the full path to the current script is, you can use that to figure out what path to use.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...