Jump to content

Recommended Posts

Here's the situation and scenario.

 

I am pulling variables from a text file and looping them through a function in order to get a result, problem is, that something is happening that is not allowing the results to pass through correctly. Weird thing is, that if there is only one variable present, the script works, if more than one variable is in the list, then that's where the problem comes in. The script only returns the correct result with the last variable in the list, all other variables seem to no be passing correctly.

 

Here is the process:

 

grab first line of text file

use that variable to request data from an ssl site using fsock

returns a result based on returned data from the post query

loops back around to start over with next variable in list.

 

 

I have tried everything that i could think of.

 

I basically want the script to reset completely as if only one variable were submitted. I am suspecting that it has something to do with the foreach() function.

 

Does it have anything to do with the session since its ssl?

 

Like I said when only one variable is present in the text file, it works accordingly. When more than one variable, it only works correctly with the last variable. The other variables return the incorrect result.

 

at the end of the file, i even manually unset every variable in the script to make sure that i starts with all variables undefined just in case and still... no dice.

 

code that i am using can be viewed at http://fontestad.net/personal/jf/pt/t.phps

 

thank you.

Please give us the code you currently have, so it will be easier for us to help you. Post it using the code tags, thank you! :)

 

Also, if you are having problems, try to debug the problem. What exactly is not working? Is it working with the data you think it is?

It is kind of working. It works with only the last variable in the list. For the rest of the variables it just gives back an incorrect results. I am suspecting that something is not passed correctly

 

I posted code at the link above. Need I post it here as well?

 

Thank you.

i'm not that great at php, so my knowledge is limited.

 

it seems as if it is nesting each variable. i just don't understand why it only returns the correct results for the last variable in the array. i'm thinking about changing the foreach loop to just a for loop and have it loop a specified number of times.

What is "it."  What are you expecting?  What is the error?  All we see is a script, we have no idea what  your intentions are.

 

function onapi() accepts zero arguments, and therefore your loop at the bottom of your script is useless, onapi() will do the same thing every time. 

 

What do you believe onapi() does?

onapi gets a variable (name) from a text file and submits it to the website (onapi.do), and depending on the result on the website (script searches for a specific string in the response), it will let me know if name is available or not.

 

the result being, that it always tells me that all the name are available (which isn't true) with the exception of the last variable in the list (which it lets me know correctly if the name is available or not).

 

so basically the script takes the first line from a text file, which is a product name, submits it to the website (onapi) and depending on the response the script lets me know if it is available or taken, then it moves on to the next name.

I figured it out.

 

It's the way that the variables (names) were being read from the text file.

 

Fixed it by using:

 

    $names = file('./t.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    $names = array_map('rtrim',$names);

 

Now everything works accordingly.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.