0

So I have the following code:

<div id="currentmotto"><?php mottoGrab($name); ?></div>

And what this does is it uses curl to screen scrape a users motto and display it on the site. What I need it to do is for that function to refresh every few seconds to see if the user has updated the motto.

I know with jquery I can use the .load('phpfile.php') but the problem then is if I put that function in that file, it no longer gets the $name variable as that is from another page.

Any ideas?

4
  • 1
    php.net/manual/en/book.session.php? Commented Nov 2, 2012 at 23:06
  • 2
    Is there any reason you can't store the name variable as a JS varible, that way you cna send the $name variable to the server through an ajax call when you want to get the file to return it's data? Commented Nov 2, 2012 at 23:06
  • If I start a session in the original page and store the name in a session variable, will this run over to the loaded page? Commented Nov 2, 2012 at 23:09
  • If you start the session there too, yes. Commented Nov 2, 2012 at 23:09

2 Answers 2

3

Pass name to phpfile.php via the query string:

.load('phpfile.php?name=THENAME');

Then grab the name from within phpfile.php using $_GET['name'] and stick it in the function.

OR

Make an AJAX request passing the name and update the page using javascript.

Sign up to request clarification or add additional context in comments.

Comments

3

Since PHP is executed server-side, it doesn't change once the client loads the page. The only way to refresh a div without JavaScript is to reload the page.

I would try using AJAX to get the name from the other file and update the HTML with JavaScript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.