# Setcookie/getcookie problem

**URL:** https://forum.kirupa.com/t/setcookie-getcookie-problem/314085
**Category:** Uncategorized
**Created:** [September 17, 2010, 6:12pm UTC](https://forum.kirupa.com/t/setcookie-getcookie-problem/314085 "2010-09-17T18:12:26Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![speedy\_rudolf](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@speedy\_rudolf](https://forum.kirupa.com/u/speedy_rudolf)
#### Post date: [September 17, 2010, 6:12pm UTC](https://forum.kirupa.com/t/setcookie-getcookie-problem/314085/1 "2010-09-17T18:12:26Z")

</div>

Hi. I’m trying to make a website where people have to login to be able to see some contents. But I kind of got stuck. I’m trying to use cookies, but I can’t get them to work. (The following code is to test if the cookies/site work)  
Login page:

```auto

<html>
<head>
<script language="javascript">
<!--
function setcookie(){
document.cookie = "logged="+escape("Dom Director")
window.location = "/site.html"}
</script>
</head>
<body onload="setcookie()"></body>
</html>

```

Site Page:

```auto

<html>
<head><title>TITLU</title>
</script>
<script language="javascript">
<!--
function getCookie(cookies){
 var results = document.cookie.match ( '(^|;) ?' + cookies + '=([^;]*)(;|$)' );
 if ( results )
  return ( unescape ( results[2] ) );
 else
  return null;}
</script>
</head>
<body>
<table width="100%">
<tr height="150"></tr>
<tr><td width="150">bara navigatie</td>
<td width="0*"><img src="400p.png">
<script>if (!getCookie('logged'))
document.write('You're not logged in.')
else
document.write('Hello , '+getCookie("logged"))</script>

```

The problem is that it doesn’t matter if I load the site page or the login page, I only get “you’re not logged in”, so either the cookie isn’t being set, or the search doesn’t find the cookie.  
Any help will be very much appreciated. Bye.
