Solved

Proper Browser redirection

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

726 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