/    Sign up×
Community /Pin to ProfileBookmark

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:
[URL=”http://bindslevdesigns.com/overview.jpg”]http://bindslevdesigns.com/overview.jpg[/URL]

Thank you very much

Lars

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyNov 22.2008 — 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.
Copy linkTweet thisAlerts:
@Lars_authorNov 22.2008 — 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
Copy linkTweet thisAlerts:
@Sup3rkirbyNov 22.2008 — 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).
Copy linkTweet thisAlerts:
@Lars_authorNov 22.2008 — 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="[email protected]" 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>[/CODE]


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=InnoDB 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');[/CODE]


Can it all just be in the same folder?

And thanks again, this is very great
Copy linkTweet thisAlerts:
@Sup3rkirbyNov 22.2008 — 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.

[code=php]
<?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 > 0 && $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'>";
}
?>
[/code]


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).
Copy linkTweet thisAlerts:
@Lars_authorNov 23.2008 — 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'];
Copy linkTweet thisAlerts:
@Sup3rkirbyNov 23.2008 — 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.
Copy linkTweet thisAlerts:
@Lars_authorNov 23.2008 — 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
Copy linkTweet thisAlerts:
@Sup3rkirbyNov 23.2008 — 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.
Copy linkTweet thisAlerts:
@Lars_authorNov 23.2008 — 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>[/CODE]


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>[/CODE]


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
Copy linkTweet thisAlerts:
@Lars_authorNov 23.2008 — 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'>";
}
?> [/CODE]


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";
?> [/CODE]


If you would like, i can give you access to my ftp server?
Copy linkTweet thisAlerts:
@Sup3rkirbyNov 23.2008 — 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";
?>
[/CODE]


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.
Copy linkTweet thisAlerts:
@Lars_authorNov 23.2008 — Yeah ok, i thought i might work so, thats why i wrote the line:
[CODE]echo "Address";[/CODE]
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.
Copy linkTweet thisAlerts:
@Lars_authorDec 09.2008 — Hey, thanks for alle your help, it has really helped me.

I just wanted to tell you, that it works ???
×

Success!

Help @Lars_ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...