Solved

Proper Browser redirection

Posted on 2004-08-17
4
242 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now