Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

    any standard code to each page use cookies for using a PHP cookie in a page ?

    I must include any standard code when using cookies to a webpage[ http://www.paphoscarhire.com/reservations.htm ] , since cookies set in home-page[ http://www.paphoscarhire.com ] like
    ---------------------------------------------------------------

    <?php
    session_start( );
    $affiliate = '10000'; //default value
    if (isset($_COOKIE['aff']) && ($_COOKIE['aff'] != Null))
    {
    $affiliate = $_COOKIE['aff'];
    }
    else if (isset($_GET['aff']) && ($_GET['aff'] != Null)) {
    $affiliate = $_GET['aff'];
    setcookie("aff", $affiliate, time()+60*60*24*90); // 3 months
    }
    $_SESSION['affiliate'] = $affiliate ;
    ?>
    ---------------------------------------------------------------

    or the small code
    <script language="JavaScript">
    <!--
    var affiliate = <?= $affiliate ?>;
    -->
    </script>

    ------------------------------------------------------------

    <input type="hidden" name="affiliate" value="<?= $affiliate ?>">
    <script language="JavaScript">
    <!--
    document.write("You book through affiliate ID: " + affiliate )
    -->
    </script>
    -------------------------------------------------------------

    only is ok in a webpage [after the code in home-page] ? If I must include it to each webpage use cookies, which part of the page to insert this standard code ?
    Tell me this for using PHP cookies and for using JS cookies ?

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't understand much of your post.

    cookies are sent to and from the browser on each request/response so you don't need to do anything special to have access to a cookie. if you set it on the first page that the user visits (with the code that you posted), then you'll be able to read the cookie on all following pages (on that same domain, for the next 90 days).
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    a)...then you'll be able to read the cookie on all following pages ::: using ONLY the small code I refer ?
    b)How I convert a PHP cookie to a js cookie ?

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    All you need is the appropriate PHP or Javascript code in the page that reads the cookie in order to access it.

    Since cookies are the same regardles of the language used to create them there is no conversion required in order to read a cookie in Javascript that was created in PHP ir vice versa.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •