Posting VARS via PHP header?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

aluminumpork
Forum Newbie
Posts: 14
Joined: Mon Oct 24, 2005 8:54 pm

Post by aluminumpork »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The code you posted there is actually almost the identical way I'm doing it.
Except instead of attached ?xmlrequest as a get, I'm adding it as a POST.

So:

[syntax="javascript"]
function startRequest(){
   ...
   var postText = 'variable=data';
   postText += 'javascript=yes';
   xmlHttp.open("POST","bar.php",true);
   xmlHttp.send(postText);
}
Except "bar.php" looks something like this:[/syntax]

Code: Select all

<?php
header('Cache-Control: none');
if($_POST['javascript']=='yes'){
   header('Content-Type: text/xml');
}

// DO MYSQL STUFF

if($_POST['javascript']=='yes'){
   echo "<results>";
   echo "<content>" . $content_data . "</content>";
   echo "</results>";
} else {
   header('Location: originalPage.php?variable=' . $data);
}

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well maybe this is a personal preference of mine, but I say you use a session. If you want to use a post variable because it only lasts for one page, unset() the session variable when you're done with it.
aluminumpork
Forum Newbie
Posts: 14
Joined: Mon Oct 24, 2005 8:54 pm

Post by aluminumpork »

Yeah, I was thinking about using a session, and I still may end up doing that. I was just afraid that it may not always work as well. That's what I will probably end up using, thanks for you help everyone!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I must be missing the point. Redirect? Session? What for?
The request tells you what the data is supposed to look like. Let the script render the data accordingly and you're done

Code: Select all

<?php
$data = fechData($_POST);
if ( isset($_POST['javascript']) && 'yes'===$_POST['javascript']) {
	ajaxdata($data);
}
else {
	htmldata($data);
}
?>
Post Reply