• Hi everyone. I hope this is the right place to post this “hack”. I have wordpress installed on one domain (iaddicshelters.net)
    AND I have another non-wordpress application on a second domain (iaddic.info). The first is a self hosted wordpress and the
    second is a windows server running a particular application.

    To execute the application on the non-wordpress domain (iaddic.info) I enter a url like this:

    https://iaddic.info/webs/cis/config/Configurator.aspx?cid=c06b50fe-e087-40b0-8434-d763fabd1515&mid=c06b50fe-e087-40b0-8434-d763fabd1515&src=C.

    The cid= is used as the filename of the result of executing the application and the mid is a specific configuration that is being run.
    The cid captures the result of running the mid configuration…

    That said: I can not just place a link to the url because every user would essentially store the information in the same file (the cid). I want to prepend the cid with the currently logged in user and date and time.

    Lets say John Harris (a made up username) is the logged in user and John is about to run the application on the iaddic.info domain; I would like the cid to now read:

    https://iaddic.info/webs/cis/config/Configurator.aspx?cid=username-timestamp-c06b50fe-e087-40b0-8434-d763fabd1515&mid=c06b50fe-e087-40b0-8434-d763fabd1515&src=C

    Does anyone know how to insert this information into the url so that when John depresses a “launch aplication” button the url will of the cid
    is prepended? In some regards this could be looked at as a concantanate of the base url the username the timestamp and the cid and mid sstring.

    Doing this will also allow John to copy this url at a leter date and retrieve the results of that partuclar session thaat
    contains his username and timestamp.

    I am really stuck here and your help is most appreciated…thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    As you say, it is simply a string concatenation problem. The username and time is readily available in the WordPress application. Exactly how this is done will depend on how and where the url is generated in the first place. In PHP, it’s a matter of assembling the data elements and stringing them together.

    You mentioned pressing a button, which can involve javascript. Options for passing information from PHP to javascript are limited. You can echo out a <script> block, or use wp_localize_script(). Then again, just string the data elements together.

    I’m a little surprised you don’t want to do something more like ...Configurator.aspx?user=John%20Harris&time=1366405018&cid=c06b50fe-..., but do whatever works for you.

    Thread Starter iaddic

    (@iaddic)

    hello @bcworlz: Here is what I have so far: I am afraid this is a little over my head. After reading and attempting maybe 100 cmbinations of coding attempts I have resorted to a form asking the user to enter a value, I pass the value to the PHP and output the url like this:

    <?php
    $id = $_POST['id'];
    $date = date("Y-m-d");
    $time = time();
    //$user = global $display_name;
    if(empty($id)){
    	echo "Please press the back arrow and fill in the text box, $date, $time, ";
    //	echo "test $user";
    } else{
    	header("Location: https://iaddic.info/webs/cis/config/Configurator.aspx?cid=$date-$id-$time&mid=c06b50fe-e087-40b0-8434-d763fabd1515&src=C");
    }
    ?>

    the page button code looks like this:

    [raw]
    <form action="shelterconfig.php" method="post"><input type="text" name="id" />
    <input type="submit" /></form>[/raw]

    I never could seem to get the user data after following maybe 10 different examples. It would always give me a 301 error…always!

    So now…is a pointer could be had to get username that would be great otherwise i’ll next need to ask for help in creating a filter that only allows the user to enter numbers and letter…i tried that a bunch of time with no success.

    Thanks for your feedback.

    Moderator bcworkz

    (@bcworkz)

    301 is not so much an error as a warning that your server is redirecting the user to a different page. This happens anytime you send a “Location: $url” header. There’s nothing you can do about it if you stick with this method.

    Possible alternatives. One is to let your server make the request and process the results, then relay them to the user. PHP offers a few HTTP request options, I prefer cURL if it is available on your server.

    Another is to have javascript or jQuery make a request directly from the user’s browser. Which of these is better, or if they are appropriate at all, will depend on what results from a request to iaddic.info.

    You can easily get the logged in username from the WP system. See Function Reference/wp get current user. In the first example, you can see that after running $current_user = wp_get_current_User();, the username would be available as an object property with $current_user->user_login. You will also see all sorts of user info is available this way. You can insert the username value into a PHP double quoted string by enclosing the object property in curly braces like so:
    $url = "$url?cid=$date-{$current_user->user_login}-$code&mid=$whatever";

    The best way to filter user input is often by only accepting values that match a particular regular expression (regexp). Unfortunately, constructing a regexp that properly allows all good input and rejects all bad input is not always that easy.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to pass user name and timestamp in url’ is closed to new replies.