I made some PHP script with a form that contains dozen of text fields, some of them like text fields arrays, others as single text field. Part of these values I try to pass to another PHP script (pChart lib script) where I read them into variables and transform into arrays as chart input. pChart script then create chart as a PNG image on disk that I planned to show bellow form that supplied chart data. I have few problems:

  • how to provide unique name for chart image to differentiate images of many users that run script at same time;
  • how to fire pChart script in order to get chart and in same time show image bellow form with data?

My tries ended with empty form and chart image above it. Do I need session or some other "tricks"? Javascript is also welcome... Thank you.

有帮助吗?

解决方案

Since you don't have any code I am not 100% sure how you are going about most things but I can still give suggestions.

For your first problem, you could use $_SERVER['REMOTE_ADDR'] to get the user's unique IP Address and the time they are using your script using $_SERVER['REQUEST_TIME']

Like this

$uniqueName = $_SERVER['REMOTE_ADDR'] . "_" . $_SERVER['REQUEST_TIME'];

As for the other problem you can just save the variables in the session so you can recall them anytime after you call the script. You could also use ajax to asynchronously call the script that created the image and then using jquery to populate the chart underneath it using the info from the form while at the same time removing form from the page.

其他提示

In order to provide unique name for chart images

Store the result of mktime() into a php variable Append this variable to the name of every input form field In the end, assign this variable to the value of a new hidden form field.

Now when you pass the submitted data, you will know the appended value of mktime() you have appended with using the value of the hidden form field you had submitted with that value... So accordingly you can fetch out all the form fields submitted!

To show image below form data

Use AJAX form submission, instead of the regular page reload type. And then you can easily show the result of the pChart script (the chart image), in a precreated wrapper below your form

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top