Page 1 of 1

Redirect the user to another page

Posted: Thu Jul 08, 2004 12:14 pm
by sathish
Hi,
Using the Linux Cron I am trying to execute a php script , mypage.php .

The PHP page is fetching data from the mysql database . Using javascript I am trying to open a POP UP WINDOW for each records of the fetched data like destination URL, querystring etc.

While POP UP, the destination URL will trigger a mail functionality .(This is the requirement flow of my client :) )

For test purpose from the shell prompt of Linux , using command php mypage.php I am trying to execute the php page.

My problem is, the triggering function of the POP UP window is not called while testing. So I am not getting the test mail from the system. But the same php script is working while running in a browser.

I have tried using header redirection, javascript document.location and also javascript window.open(url) methods.

How can I make it to work in CRON? am I doing it in a wrong way while executing in shell? Whats about the Javascript running in CRON?
Please help me to correct this problem ASAP. Thanx in advance.


The sample code of mypage.php for your reference
-----------------------------------------------------------

Code: Select all

<html>
<head>
<script language='javascript'>
 function popClose()
 {
   if (newwindow) newwindow.close();
   //window.close();
  }

  function popitup(urlData)
 {
   newwindow=window.open(urlData);
  return false;
 }
 self.setTimeout('popClose();', 15000);
</script>
</head>
<body>
<?php
   $sql = " SELECT url,toEmail ....";
   rs = mysql_query($sql);  ....

   for($i=0;$i<$num_rows;$i++)
  {
     $scriptVar="http://".mysql_result($rs,i,0)."?email=".mysql_result($rs,i,1)."";

    print("<script language="JavaScript">popitup(".$scriptVar.");</script>");

     /*
print("<script language="JavaScript">document.location="".$scriptVar."";</script>");
    */    
  }

?>
</body>
<html>
Thanx & Regards,
Sathish


feyd | added

Code: Select all

tags[/color]

Posted: Thu Jul 08, 2004 12:21 pm
by pickle
I really don't think you can. Opening a new window via Javascript is run client-side, and really doesn't have anything to do with PHP (except the fact it's output by PHP). So, running the PHP file on the command line will not execute the Javascript.

Posted: Thu Jul 08, 2004 12:31 pm
by sathish
Thanx for your reply. I used javascript. I can use header redirection method . But I need to call the destination more than once. Is there any other way to execute the URL from the PHP script? and that will helpful to solve my situation?


Sathish

Posted: Thu Jul 08, 2004 12:43 pm
by pickle
It doesn't look like you can make the same script run well in a both a browser and the command line. Why don't you just have your the file send an email right in the file, rather than loading up a new window.

Also, putting your code in [syntax=php][/syntax] tags makes it MUCH easier to read. :)

Posted: Thu Jul 08, 2004 11:35 pm
by sathish
Okay. Thanks for your reply.

Is it possible for me to execute/call the destination URL from the PHP apart from the methods what I have used above ?

So that will just trigger the URL from the php page running in the shell access. is there any solution?

Thanx & regards,
sathish

Posted: Fri Jul 09, 2004 7:10 am
by sathish
Hi ,

From Tom I got a suggestion that I can use either include() function or else fopen() to achieve my requirement.

....but remember use complete URL http://domainname/path/to/file.php for this case.

Thanks a ton to Pickle and TommYNandA!!!!!

Sathizh