[PHP] php/ajax question

2006-12-30 Thread tedd

Hi gang:

I have a small php script that behaves differently depending upon 
who's calling it. The code is:


http://www.example.com/b.php";); /* Redirect browser */
exit;?>

If the code is called directly, namely http://www.example.com/a.php, 
then the $_SESSION var is filled with "text" and the redirect is 
realized.


However, if the php script is called via ajax:

-snip- preceding ajax

function sndReq(action)
{
http.open('get', 'a.php');
http.send(null);
}

Then the $_SESSION var is filled with "test", but the redirect is not realized.

Why can't the php script redirect the browser when called via ajax ?

Thanks.

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php/ajax question

2006-12-30 Thread Mark Kelly
On Saturday 30 December 2006 18:56, tedd wrote:
> Why can't the php script redirect the browser when called via ajax ?

The browser will not be expecting a page back, and will ignore headers. 
Just some quick suggestion code, this isn't tested (except createRequest - 
I use that all the time)...

function createRequest() {
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
if (request == null) alert("Error creating request object!");
   }

function sndReq(action) {
createRequest();
var url = "a.php?action=" + Volume + "&dummy=" + new Date().getTime(); 
// random shit at the end is hack to get round browser response cacheing
request.open("GET",url);
request.onreadystatechange = updateReq;
request.send(null);
}

function updateReq() {
if (request.readyState == 4) {
var newLocation = request.responseText;
window.location = newLocation;
}
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php/ajax question

2006-12-30 Thread Fahad Pervaiz

When you use "HEADER()", an HTTP header is sent to client browser. So when
using with an ajax call the header cannot redirect the page. For the purpose
you have to use include or require. If you want to redirect client browser
to some other location then you can work around with javascripts.

But when using ajax. headers cannot redirect client browser window.

Let me know if u need any more help

--- ORIGINAL ---
Hi gang:

I have a small php script that behaves differently depending upon
who's calling it. The code is:

http://www.example.com/b.php";);
/* Redirect browser */
exit; ?>

If the code is called directly, namely http://www.example.com/a.php,
then the $_SESSION var is filled with "text" and the redirect is
realized.

However, if the php script is called via ajax:

-snip- preceding ajax

function sndReq(action)
{
http.open('get', 'a.php');
http.send(null);
}

Then the $_SESSION var is filled with "test", but the redirect is not
realized.

Why can't the php script redirect the browser when called via ajax ?

Thanks.

tedd


--
Regards
Fahad Pervaiz
www.ecommerce-xperts.com


Re: [PHP] php/ajax question

2006-12-30 Thread Paul Novitski

At 12/30/2006 10:56 AM, tedd wrote:

Why can't the php script redirect the browser when called via ajax ?



Ajax is giving PHP control over just that byte-stream that ajax is 
receiving and perhaps inserting into the page, not the full page itself.


Say you use javascript to set the src of an img to a PHP 
script.  When the request is made, PHP redirects to another 
resource.  This will affect only the image object in question, not 
the HTML page in which the image exists.


Regards,
Paul 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] mime with php4.4.4 does not work anymore

2006-12-30 Thread Rasmus Lerdorf
Roger Thomas wrote:
> I have been serving my community with Invision Power Board (IPB) v1.3.1 
> Final. Things are working well with PHP 4.3.8 and Apache 1.3.29.
> 
> Yesterday I just upgraded to PHP4.4.4 and I have problems with Excel and Word 
> attachments with IPB. Whenever I click on those attachments, I will get all 
> sorts of funny characters all over my browser screen. However, image 
> attachments are correctly displayed inline.
> 
> I added --with-mime-magic=/usr/local/apache/conf/magic to configure but 
> nothing change. If I were to roll back to PHP 4.3.8, IPB works perfectly.
> 
> What have I missed. Please advise. TIA.

I don't think anybody here can answer that without knowing how IPB
serves up those attachments.  Do they even go through PHP?  If not, then
it becomes a web server configuration issue.  If they do go through PHP,
what PHP functionality is IPB using?  Perhaps they are using the
deprecated mime_magic stuff?  They should be using pecl/fileinfo
functions if they need that stuff, but I think you will have to ask them.

-Rasmus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php/ajax question

2006-12-30 Thread tedd

At 1:30 AM +0500 12/31/06, Fahad Pervaiz wrote:
When you use "HEADER()", an HTTP header is sent to client browser. 
So when using with an ajax call the header cannot redirect the page. 
For the purpose you have to use include or require. If you want to 
redirect client browser to some other location then you can work 
around with javascripts.


But when using ajax. headers cannot redirect client browser window.



Arrggg -- that's what I was afraid of. I'll have to direct my 
attention to javascript.


Thanks.

tedd

---



Let me know if u need any more help

--- ORIGINAL ---
Hi gang:

I have a small php script that behaves differently depending upon
who's calling it. The code is:

header("Location: 
http://www.example.com/b.php";); /* 
Redirect browser */

exit; ?>

If the code is called directly, namely 
 http://www.example.com/a.php,

then the $_SESSION var is filled with "text" and the redirect is
realized.

However, if the php script is called via ajax:

-snip- preceding ajax

function sndReq(action)
{
http.open('get', 'a.php');
http.send(null);
}

Then the $_SESSION var is filled with "test", but the redirect is 
not realized.


Why can't the php script redirect the browser when called via ajax ?

Thanks.

tedd


--
Regards
Fahad Pervaiz
www.ecommerce-xperts.com



--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php/ajax question

2006-12-30 Thread tedd

At 12:55 PM -0800 12/30/06, Paul Novitski wrote:

At 12/30/2006 10:56 AM, tedd wrote:

Why can't the php script redirect the browser when called via ajax ?



Ajax is giving PHP control over just that byte-stream that ajax is 
receiving and perhaps inserting into the page, not the full page 
itself.


Say you use javascript to set the src of an img to a PHP script. 
When the request is made, PHP redirects to another resource.  This 
will affect only the image object in question, not the HTML page in 
which the image exists.


Regards,
Paul



Pul:

I'm not sure why, but this is making sense.  :-)

I suspected something like that was going on in the background.

Thanks,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php/ajax question

2006-12-30 Thread Mark Kelly
On Saturday 30 December 2006 18:56, tedd wrote:
> Why can't the php script redirect the browser when called via ajax ?

The browser will not be expecting a page back, and will ignore headers. The 
response must be handled by a function you define.

For the sake of a quick demo, if your php accepts an action via GET and 
simply prints the location for the redirect, you can do it at the client 
end. 

// example code

function createRequest() {
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
if (request == null) alert("Error creating request object!");
   }

function sndReq(action) {
createRequest();
var url = "a.php?action=" + action + "&dummy=" + new Date().getTime(); 
// random stuff at the end is hack to get round browser response 
cacheing
request.open("GET",url);
request.onreadystatechange = updateReq;
request.send(null);
}

function updateReq() {
if (request.readyState == 4) {
var newLocation = request.responseText;
window.location = newLocation;
}
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php 5 and register_globals=off gives lotsa errors

2006-12-30 Thread Wikus Moller

Hi to all.

I am having huge problems running my script, which worked fine on a
server with php 4 and register_globals turned on, on a server with php
5 and register_globals turned off.

I get errors around the area in my script where I use $_GET (not the
only error). For example the following code on my index.php file which
like many other sites I know, handles quite a large amount
if(action=="main"); etc etc. :



When I go to http://chillinglounge.net (where the error is located) I
get the following error message(s):

Notice: Undefined index: action in
C:\websites\chillinglounge.net\public_html\index.php on line 55

Notice: Undefined index: sid in
C:\websites\chillinglounge.net\public_html\index.php on line 56

Notice: Undefined index: page in
C:\websites\chillinglounge.net\public_html\index.php on line 57

Notice: Undefined index: who in
C:\websites\chillinglounge.net\public_html\index.php on line 58

Now if you would look at exactly the same script at
http://ranterswap.net you'd see absolutely no errors.

That's where I need your help. I know what is causing this error. I
believe it's the fact that register_globals is turned off.

But what I really want to know is: How do I fix it without trying to
turn register_globals on via .htaccess (because it doesn't work)?

Is there a function or some magic script that would to the trick?
Or do I have to recode my entire script and how?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php 5 and register_globals=off gives lotsa errors

2006-12-30 Thread Rasmus Lerdorf
You did more than just turn register_globals off.  You also changed your
error warning level.  You have turned notices on.  Set the same error
warning level in your PHP 4 setup and you will see exactly the same
messages.

To be notice-free, your code should look like this:

 $action = isset($_GET['action']) ? $_GET['action'] : null;

replace null in the above with whatever you want your default action to
be there if it is not provided in the URL.

-Rasmus

Wikus Moller wrote:
> Hi to all.
> 
> I am having huge problems running my script, which worked fine on a
> server with php 4 and register_globals turned on, on a server with php
> 5 and register_globals turned off.
> 
> I get errors around the area in my script where I use $_GET (not the
> only error). For example the following code on my index.php file which
> like many other sites I know, handles quite a large amount
> if(action=="main"); etc etc. :
> 
>  $action = $_GET["action"]; //line 55
> $sid = $_GET["sid"];   //line 56
> $page = $_GET["page"]; //line 57
> $who = $_GET["who"];   //line 58
> ?>
> 
> When I go to http://chillinglounge.net (where the error is located) I
> get the following error message(s):
> 
> Notice: Undefined index: action in
> C:\websites\chillinglounge.net\public_html\index.php on line 55
> 
> Notice: Undefined index: sid in
> C:\websites\chillinglounge.net\public_html\index.php on line 56
> 
> Notice: Undefined index: page in
> C:\websites\chillinglounge.net\public_html\index.php on line 57
> 
> Notice: Undefined index: who in
> C:\websites\chillinglounge.net\public_html\index.php on line 58
> 
> Now if you would look at exactly the same script at
> http://ranterswap.net you'd see absolutely no errors.
> 
> That's where I need your help. I know what is causing this error. I
> believe it's the fact that register_globals is turned off.
> 
> But what I really want to know is: How do I fix it without trying to
> turn register_globals on via .htaccess (because it doesn't work)?
> 
> Is there a function or some magic script that would to the trick?
> Or do I have to recode my entire script and how?
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php