Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:04:03+00:00 2026-05-25T21:04:03+00:00

My Xml looks like this example: <?xml version=1.0 encoding=UTF-8?> <Allvotes> <vote score=2 ip=116.971.203.221/> <vote

  • 0

My Xml looks like this example:

<?xml version="1.0" encoding="UTF-8"?>
<Allvotes>
  <vote score="2" ip="116.971.203.221"/>
  <vote score="5" ip="32.97.233.5"/>
  <vote score="3" ip="212.977.233.225"/>
  <vote score="5" ip="2.80.233.225"/>
</Allvotes>

When on my flash website (AS2), somebody press “vote” button, script in PHP getting his IP… What I want is run specyfic function, depends on his IP exist in xml file or not.

If his IP already exist, PHP send message: “ALREADY VOTED!”, when IP doesn’t exist in XML, then I want to run function which store his vote score and IP in xml.

So far I know that this PHP script not works:

$dom = new DomDocument('1.0', 'UTF-8');
$myXML = "votes.xml";
$s="";
if ($_POST['todo']=="vote"){
    $ip=$_SERVER['REMOTE_ADDR'];
    $dom->load($myXML);
    $allVotes= $dom->getElementsByTagName('vote');
    foreach ($allVotes as $vote){
        if ($vote->getAttribute('ip')==$ip){
            $s.="&msg= Already Voted";
            echo $s;
            break;
        }else{
            doOtherStuff
        }
    }
}

The problem is that this loop fire “doOtherStuff” function when IP is not in first node…

Is there any magic trick to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:04:03+00:00Added an answer on May 25, 2026 at 9:04 pm

    Why your code does not work

    To answer the immediate question: you need to defer the “already voted?” test until you have iterated over all the records:

    $alreadyVoted = false;
    foreach ($allVotes as $vote){
        if ($vote->getAttribute('ip')==$ip){
            $alreadyVoted = true;
            break;
        }
    }
    
    if($alreadyVoted) {
        $s.="&msg= Already Voted";
        echo $s;
    }
    else {
        // other stuff
    }
    

    Why you should not do it this way

    Storing your data in XML like this is a really inefficient way of doing things. You should move the data store to a database (MySql is typically easiest to set up and work with from PHP).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file looks like this: <?xml version=1.0 encoding=utf-8 ?> <PathMasks> <Mask
My main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent >
So my main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical
I'm reading an XML file that looks like this: <?xml version=1.0 encoding=utf-8?> <VehicleList> <Vehicle>
The top of my web.xml file looks like this: <?xml version=1.0 encoding=UTF-8?> <web-app xmlns=http://java.sun.com/xml/ns/j2ee
I have an XML feed that looks like this: <?xml version=1.0 encoding=UTF-8?> <productFeed version=1.0
I've got some XML, for example purposes it looks like this: <root> <field1>test</field1> <f2>t2</f2>
My xml looks like this: <nodes><skus><sku>abc</sku><sku>def123</sku></skus></nodes> I want to get all the elements with
I want to transform an XML document. The source XML looks like this: <svc:ElementList>
my xml structure looks like this: <entity id=1000070> <name>apple</name> <type>category</type> <entities> <entity id=7002870> <name>mac</name>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.