www.webdeveloper.com
Results 1 to 15 of 15

Thread: trigger action by "match" code?

  1. #1
    Join Date
    Sep 2008
    Posts
    25

    Post trigger action by "match" code?

    Hi, im looking for a code, and im not sure what to look for.
    I have 2 documents: Show_user.php and history.xml
    Both documents contain a word they have in common.
    Is it possible to create an action in a third dokument, which is triggered by the "match" in the other two dokuments?
    If its a bit blurry, then maybe til image will help:
    http://bindslevdesigns.com/overview.jpg

    Thank you very much

    Lars

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    865
    I don't know that the image helping clear up what I don't understand here.

    Can you give us more context please? For instance, this third document. Is this going to be run as a script, or just a page someone loads. And where to we get the word to 'match'? Does the user type this in?

    I'm just not sure what all this is doing, or what it is for. It would be relatively easy to make a function that searches two documents for a word, and then opens a file if a match is found in both files, but I would really like to know where this word is coming from.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Sep 2008
    Posts
    25
    A user create a profile on a homepage, and fills out "mac", this gets saved in a table in a database.
    I have an xml document on my server, which will contain this "mac" eventually, (but doesnt yet).
    This is working allready.

    Now what i cant get to work, is that when my xml script will get updated with this "mac", the database will know theres a match, and will direct you to another homepage.

    Im sorry if it is still weird, but i dont know how to explain it better :S

  4. #4
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    865
    So the real question now is, if I make a .php file to search for the 'mac'(mac address?), are you going to be sending a 'mac' to the script? I would be like a form that submits. It would send POST data to the PHP file, which I can then take that variable and search the two files(you would need to enter the file names, as I don't know where they are on your server).
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  5. #5
    Join Date
    Sep 2008
    Posts
    25
    Well the biggest problem is that i cant change the content of the xml file, because its generated by a program, but it looks like this:

    History.xml
    Code:
    <?xml version="1.0"?>
    <dataroot version="XXX" vendor="XXX" url="http://www.XXX.com" mail="XXX@XXX.com" created="11/22/2008 20:51:54" comments="XXX">
    <entry Radio="LARS" Name="Tom" Address="XX:XX:XX:XX:XX:XX" Producer="" LastSeenTime="10:14:57 11/20/2008" LastUsedTime="02:00:00 01/01/1970" Type="XXX" Services="XXX" Image="XXX"/>
    </dataroot>
    The only thing im going to use is the "Address" value.
    In my DB i have a table with two rows that looks like this:

    Code:
    --
    -- Struktur-dump for tabellen `club_new_user`
    --
    
    CREATE TABLE IF NOT EXISTS `club_new_user` (
      `Navn` varchar(255) collate latin1_general_ci NOT NULL,
      `MAC` varchar(17) collate latin1_general_ci NOT NULL,
      PRIMARY KEY  (`MAC`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
    
    --
    -- Data dump for tabellen `club_new_user`
    --
    
    INSERT INTO `club_new_user` (`Navn`, `MAC`) VALUES
    ('Tom', 'XX:XX:XX:XX:XX:XX');
    Can it all just be in the same folder?
    And thanks again, this is very great

  6. #6
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    865
    It can be in the same folder.

    Here is a pretty simple version of what I was thinking. You need to save it as a new .php file and put it on your server. Basically, you submit a form(to this .php file) and the only thing you need to send is the mac address you are looking for. This script will get that mac address and search two files for it. If a match is found in both files, it takes you to a new page. If a match is not found in both, you can redirect to a different page.

    PHP Code:
    <?PHP
    $match_string 
    $_POST['mac'];

    $file1 "";
    $file2 "";

    $compare_file1 file_get_contents($file1);
    $compare_file2 file_get_contents($file2);

    $mac_file1 strpos($compare_file1$match_string);
    $mac_file2 strpos($compare_file2$match_string);

    if(
    $mac_file1 && $mac_file2 0)
    {
      echo 
    "<meta HTTP-EQUIV='REFRESH' content='0; url=www.MacFoundAMatch.com'>";
    } else {
      echo 
    "<meta HTTP-EQUIV='REFRESH' content='0; url=www.NoMatch.com'>";
    }
    ?>
    file1 and file2 are the files you want to search. And make sure to name the mac address field, 'mac' in your form when you submit it. At the bottom you can see the two places for a website redirect. The top is if a match is found. the bottom is NO match.

    Hope this helps(and works).
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  7. #7
    Join Date
    Sep 2008
    Posts
    25
    wauw this is awesome!
    But what if the 'mac' is a changing value from the "Address tag" in the xml?
    how do i extract that, into this code?

    $match_string = $_POST['mac'];

  8. #8
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    865
    Hmm... well, in order for my code to work, you need to be able to know and get the mac address.

    I, in a way, see what you would like to do, but really I don't have a full understanding. Would you mind explaining this 'system' to me. From start to finish?

    From what I can tell so far, a user creates their profile, and in this profile, fills out a 'mac address' field. When they save their profile, you save that address in a database. But then you mention this xml file(which you say doesn't exist yet).
    Now, when is the xml file created? what script creates the file? And are you wanting to redirect the user when they log in(if there is a match)? What puts a mac address in the xml? is this automated, do you create the xml, or what?

    I really just need a few more answers if I am to give you a solution. The only way I can think of right now, if you want to get the mac address so you can send it to my script, is that you need to know who the user is, and then use your database to pull out that mac address, then check for the match. Either that or you have them enter the address themselves, like a password, and submit it to my script.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  9. #9
    Join Date
    Sep 2008
    Posts
    25
    Yeah, you are right most of the way.
    The part where it gets confusing, is that the user has nothing to do with the rest of the process. When they have filled out their profile, they are done.

    A user creates a profile, fill out the "mac field" then leaves.
    The XML is allready there, but it updates a few times a day, with more new random "Mac addresses".
    If more users have made a profile with their individual "mac address", the XML will contain some of their mac addresses, and for those it does, it will show their profile-site on my screen.

    So you can say, for those "mac adresses", that are both in the db table, and the xml file, their profile will show on my screen.
    They will show one at a time in a dias with a time of about 10 sec per profile.

    I hope this helps
    Last edited by Lars!; 11-22-2008 at 08:33 PM.

  10. #10
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    865
    i don't know what 'dias' is supposed to mean...

    Anyways, it seems you are making an admin script for you to use. But I'm still a bit confused. Basically, what decideds to put an address in the XML? are the addresses just added at random? Does the XML keep each address you add, or does it completely reset and just keeps getting more random addresses?

    I'm just not sure how this XML file works.

    I don't know if this is a solution, since I'm still not completely sure of how the problem works, but a guess would be, you need to create an array. This array needs to contain the mac addresses from your database. I believe PHP can open up the database and read 1 particular field, and just create an array along the way(adding each new address from the database to the array). Then this array needs to be sent through my script(1 at a time, in a loop), and then of course if a match is found, it would send you to a new page.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  11. #11
    Join Date
    Sep 2008
    Posts
    25
    That sounds about right
    The xml file is generated by a program, and add addresses like this:

    This is when there is only one MAC
    Code:
    <?xml version="1.0"?>
    <dataroot version="1.3.8.0" vendor="XXX" url="XXX" mail="XXX" created="11/22/2008 20:51:54" comments="XXX">
    <entry Radio="LARS" Name="Tom" Address="aa:aa:aa:aa:aa:aa" Producer="" LastSeenTime="10:14:57 11/20/2008" LastUsedTime="02:00:00 01/01/1970" Type="XXX" Services="XXX" Image="XXX"/>
    </dataroot>
    This is when there is more:
    Code:
    <?xml version="1.0"?>
    <dataroot version="1.3.8.0" vendor="XXX" url="XXX" mail="XXX" created="11/22/2008 20:51:54" comments="XXX">
    <entry Radio="LARS" Name="Tom" Address="aa:aa:aa:aa:aa:aa" Producer="" LastSeenTime="10:14:57 11/20/2008" LastUsedTime="02:00:00 01/01/1970" Type="XXX" Services="XXX" Image="XXX"/>
    <entry Radio="LARS" Name="Emil" Address="bb:bb:bb:bb:bb:bb" Producer="" LastSeenTime="10:14:57 11/20/2008" LastUsedTime="02:00:00 01/01/1970" Type="XXX" Services="XXX" Image="XXX"/>
    <entry Radio="LARS" Name="Lars!" Address="cc:cc:cc:cc:cc:cc" Producer="" LastSeenTime="20:51:37 11/22/2008" LastUsedTime="15:03:01 11/22/2008" Type="XXX" Services="XXX" Image="XXX"/>
    </dataroot>
    I will try to make it work, and write back when i have something to show

    Oh and by dias i just meant, i want to find a way to change between the "profile pages" that matches in your document
    Last edited by Lars!; 11-23-2008 at 05:31 AM.

  12. #12
    Join Date
    Sep 2008
    Posts
    25
    Now i have filled out the "compare.php" document the best i can.
    I have changed the "mac" to "Address", because thats what it is called in the history.xml and i cant change that. So i also changed the table row to "Address".
    I cant get them to match, so in the following code, i have changed the xml document to an exact copy of my "show address" script, because i figgured that must trigger the match action.

    compare.php
    Code:
    <?PHP 
    $match_string = $_POST['Address']; 
    
    $file1 = "show_users.php"; 
    $file2 = "show_users2.php"; 
    
    $compare_file1 = file_get_contents($file1); 
    $compare_file2 = file_get_contents($file2); 
    
    $Address_file1 = strpos($compare_file1, $match_string); 
    $Address_file2 = strpos($compare_file2, $match_string); 
    
    if($Address_file1 > 0 && $Address_file2 > 0) 
    { 
      echo "<meta HTTP-EQUIV='REFRESH' content='0; url=virker.html'>"; 
    } else { 
      echo "<meta HTTP-EQUIV='REFRESH' content='0; url=virkerikke.html'>"; 
    } 
    ?>
    show_users.php and show_users2.php
    Code:
    <?php
    include ($_SERVER['DOCUMENT_ROOT'] . "/connect.php");
    if (!$_SERVER)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("bindslevdesigns_com", $con);$result = mysql_query("SELECT * FROM club_new_user");while($row = mysql_fetch_array($result))
      {
      echo $row['Address'];
      echo "<br />";
      }mysql_close($con);
      echo "Address";
    ?>
    If you would like, i can give you access to my ftp server?

  13. #13
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    865
    Well, I don't want to start getting too involved. I don't think this is that serious of a problem.

    Essentially, the fact that you are 'scanning' a .php file makes things tricky. My script opens up that php file, and it sees exactly what you just pasted. So it does not get a single Address, as your 'show_users.php' code is never run(which opens the database and writes out the address).

    If you open the file in a web browser, the code is executed, and we get adresses printed on the screen. But when you open the file up(binary)(meaning, in a text editor, or such), then we see the actual code. So my script is searching this text for an address:
    Code:
    <?php
    include ($_SERVER['DOCUMENT_ROOT'] . "/connect.php");
    if (!$_SERVER)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("bindslevdesigns_com", $con);$result = mysql_query("SELECT * FROM club_new_user");while($row = mysql_fetch_array($result))
      {
      echo $row['Address'];
      echo "<br />";
      }mysql_close($con);
      echo "Address";
    ?>
    My script opens the file, and that is indeed what is in the file. I guess for this to work, you would have to be comparing a file other than a PHP document. Meaning, you would have to slightly alter your PHP code, so that it creates a new, temporary html file, and redirects you to it. Then you would simply be comparing your xml file to the newly created .html file.

    Only one more complication I see with my idea though, and that would be, the .php file would have to be loaded to update the .html file. Either that, or you convert to an AJAX solution(makes more work). An AJAX solution would be completely ideal, as you would load an HTML file, and this file could execute some PHP files on your server, while still remaining on the same page. And using the proper event handlers, you could have it execute my compare script after it has run the show_users.php file.


    I suppose you might not know much about AJAX, and so I would need to implement a solution for you. I can do this, but you would have to allow me time. I have projects of my own I'm working on, and to perfect my solution to your problem, I would need a bit of time to work on all the code and make sure it will work.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  14. #14
    Join Date
    Sep 2008
    Posts
    25
    Yeah ok, i thought i might work so, thats why i wrote the line:
    Code:
    echo "Address";
    Just to check if it worked, but i can see what you mean, that it's going to be a wierd solution.
    I dont know if i can ask so much from you, but i have just read a little bit about ajax, and it sounds like a way better solution.
    If you would help me with it i will be very thankful, and i will help with so much i can, i will study some ajax so i can understand what happens.

  15. #15
    Join Date
    Sep 2008
    Posts
    25
    Hey, thanks for alle your help, it has really helped me.
    I just wanted to tell you, that it works

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles