php-general Digest 31 Dec 2006 15:13:02 -0000 Issue 4543

Topics (messages 246294 through 246303):

Re: php/ajax question
        246294 by: Mark Kelly
        246295 by: Fahad Pervaiz
        246296 by: Paul Novitski
        246298 by: tedd
        246299 by: tedd
        246300 by: Mark Kelly

Re: mime with php4.4.4 does not work anymore
        246297 by: Rasmus Lerdorf

php 5 and register_globals=off gives lotsa errors
        246301 by: Wikus Moller
        246302 by: Rasmus Lerdorf

Best way to manage open slots for download
        246303 by: Aras

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
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;
                }
        }

--- End Message ---
--- Begin Message ---
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:

<?php session_start();   /* a.php  */
ob_start();
$_SESSION['var'] = "test";
ob_clean();
header("Location: http://www.example.com/b.php";<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

--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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:

<?php session_start();   /* a.php  */
ob_start();
$_SESSION['var'] = "test";
ob_clean();
header("Location: <http://www.example.com/b.php>http://www.example.com/b.php";); /* Redirect browser */
exit; ?>

If the code is called directly, namely <http://www.example.com/a.php,> 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
<http://www.ecommerce-xperts.com>www.ecommerce-xperts.com


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

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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;
                }
        }

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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?

--- End Message ---
--- Begin Message ---
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?
> 

--- End Message ---
--- Begin Message ---
First of all, Happy New Year for everyone in the list. I wish 2007 brings
all us happiness, health and peace.

I want to read your advises at a point i am stuck within, i have an
application that serves downloads to clients. For some reason i am limiting
total open slot for some group of users (not related to my technical
question).

Example;

// CHECKS SLOT HERE

else {  // IF THERE ANY AVAILABLE SLOTS SEND THE FILE

// INCREMENT SLOT NUMBER BY 1

$fp = fopen($pathside,"r");

if ($fp) {

        while (!feof($fp)) {
        echo fread($fp, 334);

        $bytes_out += 334;
        ob_flush();

                if ($bytes_out > $size) {

                // DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED

                }

        }

}

}


Slots are recorded and checked from a simple mysql table. Everything works
in this scenario. There is no problem if a person starts a download and
finishes it, his slots get empty upon doing so. Yet if he cancelles the
transfer, he will never reach my control structure to empty the slot. And
slots will be full of zombies.

I have thought of updating a mysql field for alive-connections in the while
loop, but it will definitely add some load on my server. Updating a system
file is not secure and good way.

What other ways can you recommend to me for the situtation?


Aras Koktas
[EMAIL PROTECTED]
Business Excellence Development
Phi.dot Internet Systems

--- End Message ---

Reply via email to