Solved

Proper Browser redirection

Posted on 2004-08-17
4
266 Views
Last Modified: 2011-09-20
Hello,

Thanks in advance!

i have a php script that submits a job to a software application; that is; it submits an input file to a software on my server (Mech engg related software) and the software gives image as an output. So after i submit the input file to the program and till the program creates the image i have to show a text like "processing please wait " and once the image gets created i have to redirect my browser to the page that shows the image to the user.

How can i go about doing it?

Thanks
0
Comment
Question by:maratmu
  • 3
4 Comments
 
LVL 5

Expert Comment

by:basiclife
ID: 11825555
OK, step 1:

You need something like:

<Job Upload> --> Holding Page
<holding page refreshes from server every X seconds until Job is done>
Holding Page --> Image

Simplest way is to assign a Job ID in a database. Get your Job Script to write a "completed" value to the database when finished.

Use PHP to check job ID (in the URL of holding page) if the Job is not finished, reload the Holding page. If it IS finished, show the Job

This is the method that is used at www.cooltext.com for their image creation.

If you want some sample code, give me a shout. If you'd rather have the challenge, I'll stay quiet :D

0
 

Author Comment

by:maratmu
ID: 11827114
it would be great if you give me that code
0
 
LVL 5

Accepted Solution

by:
basiclife earned 60 total points
ID: 11827292
Ok. Do you have a MySQL Database? I'm assuming so. If not, you'll have to modify this code. I haven't tested this so there are probably typos / silly mistakes but you get the idea.

In your upload job file, you need to write to the database. I'd suggest the database designed simply:

jobID(int)(auto_increment)           Status(tinyint)

The in your job upload code you need to

<?
// Handle the upload (You already have that, I assume) and start the processing

require(mysql_link); //See later on in this post
mysql_query("INSERT INTO jobs ( `status` ) VALUES( 0 ) ", getLink()) or die("MySQL Query Failed: ".mysql_error(getLink()));
$jobID = mysql_query("select jobID from jobs ORDER by `jobID` DESC LIMIT 1 ", getLink()) or die("MySQL Query Failed: ".mysql_error(getLink()));

header("Location: http://www.yoursite.com/holdingpage.php?jobID=$jobID");
?>


then in your holdingpage.php:

<?php
require(mysql_link);
    $ready=0;
    $result = mysql_query("SELECT Status FROM jobs WHERE jobID='" . $_GET['jobID'] . "'", getLink()) or die("MySQL Query Failed: ".mysql_error($link));
    if ($result) $row = mysql_fetch_row($result);

    mysql_free_result($result);

    if ($row)
        $ready = $row [1];

if($ready==1) {
   header("Location: http://www.yoursite.com/output.php?jobID=1234");
} else {
?>
<HEAD>
<META HTTP-EQUIV=Refresh CONTENT="10; URL=holdingpage.php?jobID=<?= $_GET['jobID'] ?>">
...

</HEAD>
<BODY>
Some nice "please wait message". Also put a link back to this page in case the browser doesn't understand META refresh tags <a href="<?="holdingpage.php?jobID=" . $_GET['jobID'] ?>">Click here to refresh</A>

</BODY>

<?php
}
?>

The above code will sit and loop every five seconds until the database is updated by your job script to say it's done, then it'll call output.php with the jobID, which will display the output form your job (you'll have to handle that)



mysql_link:

<?

$link = null;

function getLink()
{
    global $link;

    if ($link != null) return $link;

    $server="localhost";
    $database="database";

    $username="username";
    $password="password";

    $link = mysql_connect($server, $username, $password) or die("Could not connect to MySQL server");
    mysql_select_db($database, $link) or die("Could not select database $database: ".mysql_error($link));

    return $link;
}

function closeLink()
{
    global $link;

    if ($link != null)
    {
        mysql_close($link);
        $link = null;
    }
}

?>


That SHOULD do it.
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11906478
Just noticed, the Location: Header should have $_GET['jobID']  instead of 1234 (Otherwise it'll always jump to the status of Job 1234 not the curerent one.

How did the code work out?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question