Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Proper Browser redirection

Posted on 2004-08-17
4
Medium Priority
?
288 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 240 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

782 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