php cookie

Posted on 2011-10-10
Last Modified: 2012-05-12
I need some code to:

when a user logs on the site they get a page that is not the main page (info.php)
but when the revist the site the dont get the page(info.php)
Question by:beridius
    LVL 7

    Accepted Solution

    don't really understand. sound like nobody can view info.php

    when user logs in they see info.php once after that they don't see it again.
    am i right?

    setcookie("info", 1, time()+31449600);
    if($_COOKIE['info']!=1){ // show file}
    // example if($_COOKIE['info']!=1){ echo '<a href="info.php">info</a>';}

    Open in new window

    LVL 20

    Expert Comment

    by:Mark Brady
    Can you try and re ask your question. What is it that you are trying to do? Do you want to set a cookie to let you know if a user has been to your site before or not?

    If so, then a simple cookie to remember the users name would be something like this. For this example you would need to know their username and would be kept in the variable $username

    $value = $username;
    $cookieName = 'visitor';
    setcookie($cookieName, $value, time()+3600*24*365);  /* expires in 1 Year */

    The above code will write and save a cookie on the users computer. The cookie name in this case will be 'visitor'. You can name this whatever you like. The cookie expires in 1 year. you can modify the code to make it any length you want or if you want to delete the cookie, set a date in the past and it will be deleted as soon as the browser is closed.

    All it does is store the $username variable/value. To get the data in the cookie on another page or your main page you use this code...

    if (isset($_COOKIE['visitor'])) {
    // get the users name here
    $username = $_COOKIE['visitor'];

    Now you have the username in the $username variable when they revisit your website.

    Is this the sort of thing you are trying to achieve?

    LVL 107

    Expert Comment

    by:Ray Paseur

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now