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 10 of 10
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    javascript, php, cookies

    the application returns a value "1" in the database instead of the mac address...

    I'm able to document.write the output of the mac address, but not able to have it store in the database.

    Is the program using the previous cookie? (but Ive deleted all the cookies from the pc)

    but if i change the variable mac to string data, it keep refresh my webpage. Why is that so... (var mac="test data"

    Please help!

    create_users.php

    PHP Code:
    <script language="JavaScript">

    function 
    getMacAddress(){
    document.macaddressapplet.setSep"-" );
    return (
    document.macaddressapplet.getMacAddress());
    }

    function 
    setCookie(c_name,value) {
    document.cookie c_name "=" +escape(value);
    }

    //var mac="test data";
    var mac getMacAddress();


    setCookie('cookie_name',mac);
    window.location "checkAvailability.php";

    </script> 

    <script type="text/javascript">
    document.write(getMacAddress());
    </script> 
    checkAvailiability.php
    PHP Code:
    $dbhost 'localhost';
    $dbuser 'root';
    $dbname 'registration';
    mysql_connect($dbhost$dbuser) or die("Could not connect database");
    mysql_select_db($dbname);
    $javascript_cookie_value = isset($_COOKIE["cookie_name"]) ? $_COOKIE["cookie_name"] : 1;
    mysql_query("INSERT INTO test (mac) VALUES ('$javascript_cookie_value')"); 

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    In JS, when you use a variable for an identifier, do you still need to wrap it up with its single quotes? I'm not a JS kinda guy, but the only thing I can think of that may be an issue is:
    Code:
    document.cookie = c_name + "=" +escape(value);
    Many years ago when I learned js, I recall cookies were set with document.cookie = 'name=value'; combination. So I'm thinking that you still need them quotes:
    Code:
    document.cookie = "'" + c_name + "=" + escape(value) + "'";
    Also, get used to having a 1 for you're result anyway. Mac's require a client technology to retrieve, and only if the system supports and allows it. I assure you that no java program will have system access on my machines, nor will I be using internet explorer.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Do you have any idea where the value "1" come from??

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by kennedysee View Post
    Do you have any idea where the value "1" come from??
    The value "1" is coming from the default value in this line if the cookie isn't set:
    PHP Code:
    $javascript_cookie_value = isset($_COOKIE["cookie_name"]) ? $_COOKIE["cookie_name"] : 1
    Because this line isn't working:
    PHP Code:
    var mac getMacAddress(); 
    Replace with this line for error checking:
    PHP Code:
    var mac="test data 556 555 777"
    If the test data is sent to the cookie post in the Javascript Forum and ask them why this line does not work:
    PHP Code:
    var mac getMacAddress(); 

    ----------
    Last edited by Len Whistler; 01-27-2010 at 08:37 AM.
    Leonard Whistler

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Is that possible that i set my cookie expiry to 1day with,

    Code:
    function setCookie(c_name,value) {
    document.cookie = c_name + "=" +escape(value);
    }
    TO

    Code:
    function setCookie(c_name,value,1) {
    document.cookie = c_name + "=" +escape(value);
    }

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by kennedysee View Post
    Is that possible that i set my cookie expiry to 1day with,

    Code:
    function setCookie(c_name,value) {
    document.cookie = c_name + "=" +escape(value);
    }
    TO

    Code:
    function setCookie(c_name,value,1) {
    document.cookie = c_name + "=" +escape(value);
    }
    No expiry date is set, and I don't know what the default expiry date is for cookies.


    ---------------
    Leonard Whistler

  • #7
    New Coder
    Join Date
    Jan 2010
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Is that possible to have it code when the user visit the webpage, the system will automatically delete the cookie and store this current cookie?

  • #8
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by kennedysee View Post
    Is that possible to have it code when the user visit the webpage, the system will automatically delete the cookie and store this current cookie?
    Just give the cookie the same name, it will overwrite the original cookie.


    -----------
    Leonard Whistler

  • #9
    New Coder
    Join Date
    Jan 2010
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Len Whistler View Post
    The value "1" is coming from the default value in this line if the cookie isn't set:
    PHP Code:
    $javascript_cookie_value = isset($_COOKIE["cookie_name"]) ? $_COOKIE["cookie_name"] : 1
    Because this line isn't working:
    PHP Code:
    var mac getMacAddress(); 
    Replace with this line for error checking:
    PHP Code:
    var mac="test data 556 555 777"
    If the test data is sent to the cookie post in the Javascript Forum and ask them why this line does not work:
    PHP Code:
    var mac getMacAddress(); 

    ----------
    Even i replace the line for error checking:
    PHP Code:
    var mac="test data 556 555 777"
    My internet explorer keep refreshing non-stop, same for my Firefox.

  • #10
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by kennedysee View Post
    Even i replace the line for error checking:
    PHP Code:
    var mac="test data 556 555 777"
    My internet explorer keep refreshing non-stop, same for my Firefox.
    This is the original code and it works with the test data.

    php grabbing data from javascript

    The var mac = getMacAddress(); line will have to be sorted out in the Javascript Forums.




    ---------------------
    Leonard Whistler


  •  

    Posting Permissions

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