1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP/Javascript Puzzle

Discussion in 'PHP' started by Weirfire, Apr 18, 2005.

  1. #1
    First of all I just want to say what a numptey I am.

    I was trying to assign a Javascript function return variable to a PHP variable. Here's the exact code I was writing;

    $TimeStamp = "<SCRIPT LANGUAGE='JAVASCRIPT'>getTimeStamp();</SCRIPT>";
    Code (markup):
    The puzzle I am looking to solve is whether there is a way of generating a timestamp in PHP which does exactly the same job as

    <SCRIPT LANGUAGE="JavaScript">
    
    function resetDynamicFields()
    {
    	return Date().valueOf();
    }
    </SCRIPT>
    Code (markup):
    Thank You in advance. :)
     
    Weirfire, Apr 18, 2005 IP
  2. TommyD

    TommyD Peon

    Messages:
    1,397
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Php code is interpeted/executed on the server. Javascript is interpeted/executed by the browser. So this is a case of the carrage before the horse.

    So, before just spouting out php or js code, let me ask, are you using the timestamp specificly for php functions? Or do you need it(the same value) also for JS(browser) functions?

    tom
     
    TommyD, Apr 18, 2005 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Forget it. I've tried it before and real time interaction between the two is a nightmare.

    The $timestamp will now be filled with a script.

    It might work with eval or what not but I (with my then basic PHP knowledge and limited JS experience) couldn't work it out...
     
    T0PS3O, Apr 18, 2005 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    It's actually to be used for a PHP function which is the bizarre thing. It was created for an oscommerce MOD and they had the Javascript posting back to itself so that the value could then be assigned using $_POST['TimeStamp'].

    All I need is;

     
    Weirfire, Apr 18, 2005 IP
  5. TommyD

    TommyD Peon

    Messages:
    1,397
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Guessing you need it for performing Server side issues.

    If you don't mind using the server to generate the timestamp(typical if you work with people in different timezones, and are guareenteed their computer time is set correctly), then just used this:

    $TimeStamp = microtime();


    Reference: http://us2.php.net/manual/en/function.microtime.php

    hth,

    tom
     
    TommyD, Apr 18, 2005 IP
  6. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #6
    thanks tommy

    Its really just as a unique identification for each order that is passed through. I dont know why hsbc insist on it. mind you i dont know why they insist on a lot of things. :rolleyes:
     
    Weirfire, Apr 18, 2005 IP
  7. TommyD

    TommyD Peon

    Messages:
    1,397
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Personally I don't like using timestamps as identifification. I've had discussions how a multi-threaded process could technically handle two check outs at the same exact time. So, we always tied it to the user id(or what ever unque key you use to identify customer).

    But this was on a J2EE ecommerce site.

    Glad I could help.

    later,

    tom
     
    TommyD, Apr 18, 2005 IP
  8. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8
    http://us2.php.net/manual/en/function.uniqid.php
     
    mushroom, Apr 18, 2005 IP
  9. andriar

    andriar Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hi there,
    have you actually found a way to calculate that 13 digit timestamp?
     
    andriar, Jun 8, 2006 IP
  10. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #10
    Wow you rewoke an old thread. What is it you're looking to do andriar?
     
    Weirfire, Jun 8, 2006 IP