Jump to content


Photo

Loading two scripts simultaneously


  • Please log in to reply
10 replies to this topic

#1 Rushyo

Rushyo
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 03 April 2006 - 07:54 PM

I've got an AJAX engine which sends through an XML document to a PHP script, which then parses it into a set of urls like below:

loadpage.php?example=bleh
loadmenu.php?example=poot

Now, to the important bit... how can I load up more than one url at a time? I want to run loadpage.php and loadmenu.php and get them both to send data back to the client. I'm not asking for an 'alternative' method I simply need to know how to do this, if it is possible.

One plausible method is if PHP allows you to send HTTP requests to both pages... like so:

MakeRequest("loadpage.php?example=bleh");
MakeRequest("loadmenu.php?example=poot");

Obviously I can't use the header() function since I need to load two scripst from one script... and I can't change the header twice.

NOTE: My server using PHP 4.
Private message me if you need help securing your PHP, ASP, Apache, IIS and SQL assets. Offering great SSL solutions for cheap!

Security Analyst
PUSH 55 Security Solutions

#2 yellow1912

yellow1912
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 April 2006 - 08:04 PM

I think you can do it only 1 by 1 (PHP is not multi-threaded, is it?). But maybe Im wrong.
If you want to do it it 1 by 1, then use include or require.

#3 Rushyo

Rushyo
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 03 April 2006 - 08:08 PM

that only includes it, it doesn't give it a whole new set of POST/GET data to work with.

I was thinking something along the lines of CURL... but that might actually be available on my shared hosting.
Private message me if you need help securing your PHP, ASP, Apache, IIS and SQL assets. Offering great SSL solutions for cheap!

Security Analyst
PUSH 55 Security Solutions

#4 yellow1912

yellow1912
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 April 2006 - 08:19 PM

You can, I did it before, just include(loadmenu.php?example=poot);
If you want to pass by POST then you can use curl
// SET URL FOR THE POST FORM LOGIN
        curl_setopt($ch, CURLOPT_URL, 'linkkkkk');
        
        // ENABLE HTTP POST
        curl_setopt ($ch, CURLOPT_POST, 1);
        
        // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
        curl_setopt ($ch, CURLOPT_POSTFIELDS, "login=something&password=somwthing);


#5 Rushyo

Rushyo
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 03 April 2006 - 08:29 PM

Tried the include approach... it executed neither of the scripts.

Ammendum: I figure CURL won't work because it operates in the same way 'header' does, it tells the user's browser to execute the request, which I believe won't work with AJAX since it points the user's browser away from the initial page.

I'll have a try though
Private message me if you need help securing your PHP, ASP, Apache, IIS and SQL assets. Offering great SSL solutions for cheap!

Security Analyst
PUSH 55 Security Solutions

#6 yellow1912

yellow1912
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 April 2006 - 08:37 PM

Tell me what result do you expect from calling the script? You want some parameters returned or something?

for curl set curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); --> Then all the result will be return as a string instead of being displayed.

#7 Rushyo

Rushyo
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 03 April 2006 - 08:48 PM

Each of the two scripts are simply for testing and read:

<?php

$ajax = "main|";
$ajax = $ajax."Main";
echo($ajax);

?>

and

<?php

$ajax = "menu|";
$ajax = $ajax."Menu";
echo($ajax);

?>

What they should do is slot into the original HTML document like so:

<div id="main">Main</div>
<div id="menu">Menu</div>

This is how the AJAX engine handles any responses from the scripts.

If I make a call to one of them, it works fine but not if I try to call both (using the obviously flawed header method, which I knew would fail but it proves the rest of the code is working since it works in a single instance)
Private message me if you need help securing your PHP, ASP, Apache, IIS and SQL assets. Offering great SSL solutions for cheap!

Security Analyst
PUSH 55 Security Solutions

#8 yellow1912

yellow1912
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 April 2006 - 08:53 PM

Pls read php.net:
[a href=\"http://us2.php.net/manual/en/function.include.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.include.php[/a]

Many good examples listed there. Anyway, Im so sleepy and gotta take a nap now, hope you can find the solution or someone can help.

Cheers.

err, just saw yor reply, try this:
in your included script, echo everything you want to display:
echo " blah blah blah --- This is the main";

PS: If possible post your script here or pm me, at least part of it

#9 Rushyo

Rushyo
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 03 April 2006 - 09:00 PM

I can't help but feel that was meant as an insult to my intelligence.

As I've already told you I've tried implementing include, if only just to shut you up after the first time I told you it wouldn't work. You quite clearly don't know how AJAX works, this isn't just slapping a web page on the client, it's about modifying one already on the client machine.

[!--quoteo(post=361346:date=Apr 3 2006, 09:53 PM:name=yellow1912)--][div class=\'quotetop\']QUOTE(yellow1912 @ Apr 3 2006, 09:53 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]err, just saw yor reply, try this:
in your included script, echo everything you want to display:
echo " blah blah blah --- This is the main";

PS: If possible post your script here or pm me, at least part of it
[/quote]

$ajax = "menu|";
$ajax = $ajax."Menu";
echo($ajax);

That's what it already does...
Private message me if you need help securing your PHP, ASP, Apache, IIS and SQL assets. Offering great SSL solutions for cheap!

Security Analyst
PUSH 55 Security Solutions

#10 yellow1912

yellow1912
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 April 2006 - 09:01 PM

Rushyo, I feel all asleep and I still trying to stay up to help you. And i never in my life insult anyone's intelligence or whatsoever, except mine.

And I for one wouldnt get angry at someone who trying to help me, even if he is of use or not. You will never get any friend this way.

#11 Rushyo

Rushyo
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 03 April 2006 - 09:14 PM

"And I for one wouldnt get angry at someone who trying to help me, even if he is of use or not. You will never get any friend this way."

If that person is implying I'm stupid, I wouldn't want to be friends with them.

Forget it, I'll find some way around it myself.
Private message me if you need help securing your PHP, ASP, Apache, IIS and SQL assets. Offering great SSL solutions for cheap!

Security Analyst
PUSH 55 Security Solutions




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users