Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie Question... 1

Status
Not open for further replies.

coldfused

Technical User
Jan 27, 2001
2,442
US
Can I do this?

Home page set a cookie and give it the variable of:

"page=1"

Rest of pages check for variable "page=1"

if page = 1 the page now = 2
elseif page = 2 page now = 3

if page = 3 popup window open

What i want to do is trac users to a third page view, once on the third page view i would like to have a teaser ad pop up enticing them to sign up for special giveaway.

Now i know all about pop ups and cookie browser issues so i dont really need to hear all the details on why i should not do this.

My boss insist that we do this because he heard it somewhere and wants to get it done, so i am forced to find a solution.

Anyone have any ideas on how to impliment this, i'm not that familiar with cookies so an example would be great if someone new how and had the time.

Thanks in advance,

---------------------------------------------
 
php?
asp?

in php

<?php
setcookie("page", "1", time()+86400*30);
?>

///Sets it to expire in 30 days

<?php
if (!isset($HTTP_COOKIE_VARS['page']) || $HTTP_COOKIE_VARS['page'] != "1") {
header ("Location: donotmatch.php");
}
?>

///check to see if cookie is "1" if not then redirects

Listen All I ask is that You close out a Post You Started!!!!
 
Couldn't you use a javascript onLoad function to display the pop-up when the user opens page 3?

There's always a better way. The fun is trying to find it!
 
Also deecee thanks for that as well. Unfortunately the pages are all static html stuff, old dinosaur sites from previous designers of the company I work for during the day.

I had a friend explain I could do what you suggest and just rename the extensions of the pages to php or something.

About 15 sites total (hotels, realestate, building supply, etc), some with tons of pages so I would rather not do that.

So my best option would probably be the javascript thing.

---------------------------------------------
 
Javascript can detect when a page is loading (onLoad) and you can use this to do a number of things, one of which is to open a pop-up window. Check the javascript forum for more details but basically you would do something like this to your pages:

<body onLoad="popPage()";>

and you would create a javascript function called popPage() that contained the javascript code to open and display your pop-up. (Javascript can reside on your web page or an external file.)

By the way, you can't just rename your web pages with a .php extension. PHP is a server-side scripting language and your pages have to have PHP code in them in order for them to use PHP. Additionally, not all web hosting companies offer or support PHP so before you jump into something like that, check with your web host.

There's always a better way. The fun is trying to find it!
 
Um....

Ok I understand about pop ups and onload javascript functions. I also am aware of hosting companies and file extensions.

What I dont know is how to detect when the third page has been opened from the index and pop up a page only if the third from the index has been reached.?

And third from index could be anyone of the pages in the site.

---------------------------------------------
 
Okay, I understand what you want know. I thought it was the third page in a definate list but you want it to be the third page opened, regardless of the order they were opened. In this case, I think the easiest way is going to be with a cookie. Unfortunately, not everyone allows cookies. If you chose this option, you could always notify the user that your site uses cookies.

There's always a better way. The fun is trying to find it!
 
whos not everyone? if anyone does any online shopping then they do -- also you have as high a chance for Javascript to be turned off as you do cookies. IMHO id rely more on Server Side Scripting where I can than client Side (for most instances).

zzzzzz
 
Guys thanks for trying to help but i'm really getting no where with this.

From the topic of my post tviman I understand I have to use a cookie, that'not my question.

Do you have an example of how I would use a cookie to get the results I need?

Deecee thanks for your advice but server side is out of the question, not my descision to make. Company would not do the switch without charging the clients, clients will not want to switch when it works like it is.

Trust me when I say Dinosaur`s...

---------------------------------------------
 
Virt this might work for you.

javascript to write the cookies:

Code:
<script language="javascript">

function setPageNumber(){
   //Insert current page number
   var currentPageCount = getCookie("pageNumber");

   if (getCookie("pageNumber")==null){//if there is no cookie
      document.cookie="pageNumber=1";//create the cookie
   }
   else{
      incrementPageNumber(currentPageCount);//add 1 to the "pageNumber" value
   }
}

function incrementPageNumber(i){
   if (i != 2) { //if the page number is not equal to 2
      i++;  //add one to the page number
      document.cookie="pageNumber="+i;  //and write it to the cookie
      alert(getCookie("pageNumber")); //for testing remove when live
   }
   else{
   //open the pop up window
      if (getCookie("windowOpened") != "true"){ //if the window hasn't already been opened
		window.open('popup.htm','advertisement','width=200,height=200');
		document.cookie="windowOpened = true";
		}
   }
}
//function to read cookie

function getCookie(Name) {
var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}
window.onload = setPageNumber;

</script>

I hope it helps!

Wow JT that almost looked like you knew what you were doing!
 
Yes that's it. I would put it in a scripts.js file in the same folder:

Then just a <script language="javascript" src="scripts.js">.

Wow JT that almost looked like you knew what you were doing!
 
Hi!

Right off the top of my head I can not see why this wouldn't work on a Mac. Do you know what browser the Mac is using?

I will try it at home on my Mac (OSX) and see if I can figure it out.

Wow JT that almost looked like you knew what you were doing!
 
Well I didn't try Safari (I'm on OS 10.1) but the script worked as written above in both Netscape 7.1 and IE 5.2 on my Mac.

Is it giving you an error? Line number... anything?

What is it exactly that isn't working.

Let me know! :)

Wow JT that almost looked like you knew what you were doing!
 
Of course it works fine on my work PC. I will try again on my Mac when I get home today.

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top