Solved

Proper Browser redirection

Posted on 2004-08-17
4
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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