Question
Make a form like this using javascript and php with cookies ..need help?
NOTICE Most of the features of Word have been disabled because it hasnt been activated. Activate Example form layout: and th
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Set cookie through PHP and get through JavaScript
<?php

$myDomain = ereg_replace("^[^.]*.([^.]*).(.*)$", '1.2', $_SERVER['HTTP_HOST']);
$setDomain = ($_SERVER['HTTP_HOST']) != "localhost" ? ".$myDomain" : false;
setcookie ("site", 'http://only-your-views.blogspot.com', time()+3600*24*(2), '/', "$setDomain", 0 );
// You can change (2) to any negative value (-2) for deleting it. It is number of days for cookie to keep live. Any -ve number will tell browser that it is useless now.
?>

Page: get_cookie.html

<script>
function readCookie(name) {
        var cookiename = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);
        }
        return null;
}
document.write("n" + readCookie('site'));
</script>

. Set cookie through JavaScript and get through PHP

Page: set_cookie.html

<script>
document.cookie = 'name=David' ;
</script>
Page: get_cookie.php
<?php
var_dump($_COOKIE['name']);
?>

3. Set cookie through JavaScript and get through JavaScript

<script type="text/javascript">
days = 3; // -ve for deleting it.
var date = new Date();
date.setTime(date.getTime ()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
document.cookie = 'language=ruby' + expires;
function readCookie(name)
{
        var cookiename = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);
        }
        return null;
}
// refresh the page for getting the value or use this line in another page
document.write("n" + readCookie('language'));
</script>

4. Set cookie through PHP and get through PHP

<?php
//$_SERVER['HTTP_HOST'] = 'http://www.example.com ';
// localhost create problem on IE so this line
// to get the top level domain
$myDomain = ereg_replace('^[^.]*.([^.]*).(.*), '1.2', $_SERVER['HTTP_HOST']);
$setDomain = ($_SERVER['HTTP_HOST']) != "localhost" ? ".$myDomain" : false;
setcookie ("site2", 'http://only-your-views.blogspot.com', time()+3600*24*(2), '/', "$setDomain", 0 );
echo @$_COOKIE ['site2'];
?>

5. Set the Array Cookies

<?php
setcookie("cookie1[0]", "cookiethree");
setcookie("cookie1[1]", "cookietwo");
setcookie("cookie1[2]", "cookieone");
// after the page reloads, echo them out
if (isset($_COOKIE['cookie1']))
{
        foreach ($_COOKIE['cookie1'] as $name => $value)
        {
                echo "cookie1[$name] : $value <br />n";
        }
}
?>

6. Delete all Cookies through PHP

<?php
foreach ($_COOKIE as $k=>$v)
{
        if (is_array($_COOKIE[$k]))
        {
                foreach ($_COOKIE[$k] as $key=>$val)
                {
                        setcookie($k.'['.$key.']',"", time()+3600*24*(-100));
                }
        }
        setcookie($k,"", time()+3600*24*(-100));
}
?>
Add a comment
Know the answer?
Add Answer to:
Make a form like this using javascript and php with cookies ..need help? NOTICE Most of the features of Word have been disabled because it hasn't been activated. Activate Example form layout:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • FUN Clipboard PRODUCT NOTICE Most of the features of Excel have been disabled because it hasn't...

    FUN Clipboard PRODUCT NOTICE Most of the features of Excel have been disabled because it hasn't been activated. Activate 554 1 The Statement of Cash Flows 2 Using Excel to prepare the statement of cash flows, indirect method 4 The James Island Clothing Company began operations on July 1, 2018 5 The adjusted trial balance as of December 31, 2018, appears below, along with transaction data for 2018. JAMES ISLAND CLOTHING COMPANY Adjusted Trial Balance 12/31/18 Account Title Cash Accounts...

  • Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on...

    Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on the client side before it is submitted to the server. It is done everywhere because it is fast and it gives you a great deal of flexibility in how you handle errors insofar as the GUI is concerned. Attached is an image of some code I wrote (so Blackboard can't mess it up). Some things to notice that will help you with the lab....

  • can contain vi XPIRED Most of the features of Word have been disabled. Reactivate exceeding benefits is premised on the concept of absolute assurance. d. 29). A voucher system is a series of p...

    can contain vi XPIRED Most of the features of Word have been disabled. Reactivate exceeding benefits is premised on the concept of absolute assurance. d. 29). A voucher system is a series of prescribed control procedures a. to check the credit worthiness of customers. b. designed to assure that disbursements by check are proper. c. which eliminates the need for a sales journal d. specifically designed for small firms who may not have checking accounts. 30). Under a voucher system,...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • Assignment 4 Real Deal: Crier On Us Some word games, like Scrabble, require rearranging a combination of letters to make...

    Assignment 4 Real Deal: Crier On Us Some word games, like Scrabble, require rearranging a combination of letters to make a word. This type of arrangement is generally referred to as an anagram, it's known as a permutation in mathematics. This assignment will give you some experience thinking about and writing recursive functions. Write a C++ program that searches for ``anagrams'' in a dictionary. An anagram is a word obtained by scrambling the letters of some string. For example, the...

  • i have the case study question with the answers but i need help to re-write the...

    i have the case study question with the answers but i need help to re-write the answers. please see the attached files Case Study Analysis (CSF3003) Assessment Description and Requirements CLO1: Case Study 1 Ahmad lef home to study master and PhD in Australia. He has fees for the first semester only. After he arrived to Sydney and settled down, he start looking for a part-time job to save money for the next term. Ahmad has some experience on making...

  • Help I have taken this test so many times : These tests are intended for master's...

    Help I have taken this test so many times : These tests are intended for master's and doctoral students. Read these directions carefully! The below test includes 10 questions, randomly selected from a large inventory. Most questions will be different each time you take the test, You must answer at least 9 out of 10 questions correctly to receive your Certificate. You have 40 minutes to complete each test, and you must answer all 10 questions in order to to...

  • 23. What is the total net amount of capital gain reported on Form 1040? OA. $308...

    23. What is the total net amount of capital gain reported on Form 1040? OA. $308 OB. $2,411 C. $2,719 OD. $2,900 Advanced Scenario 7: Mark and Barbara Matthews Directions Using the tax software, complete the tax return, including Form 1040 and all appropri- ate forms, schedules, or worksheets. Answer the questions following the scenario. Note: When entering Social Security numbers (SSNs) or Employer Identification Numbers (EINS), replace the Xs as directed, or with any four digits of your choice....

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT