Jump to content

Change Image for the returning visitors.


zlatangu
Go to solution Solved by Ch0cu3r,

Recommended Posts

How are you tracking visitors?  With a login process perhaps?  You have to know some way of who's who, unless you simply want to track the ip address, which won't be at all accurate.

 

So - you log someone in.  If they already existed, you change the background on the next page load.  Simple?

Link to comment
Share on other sites

How are you tracking visitors?  With a login process perhaps?  You have to know some way of who's who, unless you simply want to track the ip address, which won't be at all accurate.

 

So - you log someone in.  If they already existed, you change the background on the next page load.  Simple?

 

No you are not understanding me. I can use cookie for letting the script know that the visitor have been on that page before and than load the second image instead of the first one. Just that I don't know to code in php, can you help me please.

Link to comment
Share on other sites

  • Solution

You'd use setcookie to set the cookie

 

Then using isset to check if the cookie exists in the $_COOKIE superglobal. If the cookie exist you'd show the second image otherwise show the first image

 

Read the documentation to the linked pages above, study the code examples to see how they are used. From the pseudo code  below you show be able to implement what you are trying to do in PHP

/*before any output*/
set the 'visited' cookie

/* in your HTML page you'd have this if statement*/
if(isset cookie 'visited')
{
    /*output second image*/
}
else
{
    /*output first image*/
}
Link to comment
Share on other sites

 

You'd use setcookie to set the cookie

 

Then using isset to check if the cookie exists in the $_COOKIE superglobal. If the cookie exist you'd show the second image otherwise show the first image

 

Read the documentation to the linked pages above, study the code examples to see how they are used. From the pseudo code  below you show be able to implement what you are trying to do in PHP

/*before any output*/
set the 'visited' cookie

/* in your HTML page you'd have this if statement*/
if(isset cookie 'visited')
{
    /*output second image*/
}
else
{
    /*output first image*/
}

OK from the following code i got just a blank page

<?php
/*before any output*/
set the 'visited' cookie

/* in your HTML page you'd have this if statement*/
if(isset cookie 'visited')
{
   
  print ("second") 
    /*output second image*/
}
else
{

print ("first")
    /*output first image*/
}
?>
Link to comment
Share on other sites

As Chocu3r said "From the pseudo code below...". 

 

What you wrote is NOT code.  You simply echoed the 'pseudo code' he wrote.  Do you not know the meaning of 'pseudo'?

 

You really need to learn how to write php.  That means reading.  And reading some more.

 

Did I mention learning?

Edited by ginerjm
  • Like 1
Link to comment
Share on other sites

actually you haven't learned.  Yes you wrote some rudimentary php code but it is flawed.  Besides the intermingling of html and php code needlessly, you did not read the entire manual page covering setcookie.  If you had you would realize that you cannot set a cookie and 5 lines later check for its existence.  Cookies are not 'real' until the page has refreshed.  And I'm pretty sure you didn't read all the documentation since your cookie is malformed to begin with.

 

And to top it all off the html you are outputting for your image display is also bad.

Link to comment
Share on other sites

actually you haven't learned.  Yes you wrote some rudimentary php code but it is flawed.  Besides the intermingling of html and php code needlessly, you did not read the entire manual page covering setcookie.  If you had you would realize that you cannot set a cookie and 5 lines later check for its existence.  Cookies are not 'real' until the page has refreshed.  And I'm pretty sure you didn't read all the documentation since your cookie is malformed to begin with.

 

And to top it all off the html you are outputting for your image display is also bad.

Yes what you are saying is true. But for now this was what I needed for my website.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.