Jump to content

Forward to another page


PHPLRNR

Recommended Posts

Yes there is buddy

 

<?php

// Put this code in the header of your HTML file * Edit PHP as needed//

echo "<script language=\"Javascript\">
function forward(){
  location.href="http://www.website.com";
}
</script>";

To forward when a user clicks a button, in the button tag include --

 

onClick = "forward()";

 

To forward automatically after so many seconds add this to the body tag

 

onload=setTimeout('forward()',5000) 

Where '5000' means 5 seconds [1000 = 1 sec]

 

Hope this helps

 

Steve

Link to comment
Share on other sites

  • 2 weeks later...

Lol if you want to get technical he said

 

 

in PHP

 

ahem

 

in - not with

 

I also find it amusing your critiquing me for using javascript when we are in the javascript forum ... I think the author was trying to say something ...  ::)

 

 

 

<META> Tags aren't PHP either.... just trying to be creative and help someone out ... but yeah Xurion, thinkin inside the box usually solves the problem   :P

 

META isn't PHP either...

 

Only way to forward to another page (with PHP only) is to header('location: yourpage.php')

 

 

Meta tags aren't php???? :o

 

Link to comment
Share on other sites

aren't = are not

 

now try reading this post again

 

Quote from: Skittalz on Today at 10:08:47 AM

<META> Tags aren't PHP either.... just trying to be creative and help someone out ... but yeah Xurion, thinkin inside the box usually solves the problem 

 

 

 

Quote from: Xurion on Today at 10:47:18 AM

META isn't PHP either...

 

Only way to forward to another page (with PHP only) is to header('location: yourpage.php')

Link to comment
Share on other sites

Yes, but it must be called before any actual output is sent. There are alot of instances in which this is the case...

 

so in those instances javascript would be key ...

 

I believe the author of this post must have ran into on of these instances hence why he asked an alternative way to forward pages  ;)

Link to comment
Share on other sites

Yes, but it must be called before any actual output is sent. There are alot of instances in which this is the case...

 

so in those instances javascript would be key ...

 

I believe the author of this post must have ran into on of these instances hence why he asked an alternative way to forward pages  ;)

 

Then better application design is needed, not a JavaScript workaround that dosen't address the cause of the potential 'headers already sent' problem.  A well designed application processes requests first, then renders output, thus avoiding the problem entirely.

Link to comment
Share on other sites

I agree with Nightslyr. Header redirects can always be done before output is sent to the browser if the application is designed well.

 

Or he could use javascript which does what he wants it to do effectively without any errors and without reconstructing his program. Why make this harder then it needs to be?

 

For the exact reasons I said before:

 

1) If the user has javascript turned off in their browser (and noscript is one of the most popular firefox plugins there are), the redirect won't work.

2) Search engines don't use javascript, so the redirect will fail for them, leaving any data on the other side of the redirect effectively invisible to the search engines. On top of this, I've read that the search engines actually penalize for javascript AND metatag redirects. So for anyone who is concerned with getting a good ranking, they would be better off using php headers.

 

It's not a matter of making things harder than they need to be, it's a matter of using the most reliable, search-engine friendly method.

Link to comment
Share on other sites

Not only that, but a lot of the issues that come up in this forum are directly related to application design.  I mean, how many threads have been started that are basically "Help, I can't get my JavaScript and PHP to behave properly?"  I believe that stressing good application design, in conjunction with helping them with their immediate coding problem, is a better solution than just giving them the code to fix it.

 

That's one of the reasons why I cringe whenever I see people give code like:

<body onload="someInitFunction();">

.
.
.

<?php while($row = mysql_fetch_assoc($result))
{
   echo "<a href=\"{$row['url']}\">{$row['linkName']}</a>";
} ?>

.
.
.

<input type="submit" name="submit" value="Submit" onclick="alert('You clicked me!'); return false;" />

 

This is NOT GOOD DESIGN!!!!!  It's hard to edit, hard to debug, and necessitates copy-&-paste coding, which is bad.  Separating the code into logical segments produces much better results:

<?php
.
.
.

$output = "";

while($row = mysql_fetch_assoc($result))
{
   $output .= "<a href=\"{$row['url']}\">{$row['linkName']}</a>";
}

.
.
.
?>

<html>
<head>
   <script type="text/javascript">
      function someInitFunction()
      {
         var submit = document.getElementById('submit');

         function showAlert()
         {
            alert('You clicked me!');
            return false;
         }

         submit.onclick = showAlert;
      }

      window.onload = someInitFunction;
   </script>
</head>

<body>

.
.
.

<?php echo $output; ?>

.
.
.

<input type="submit" name="submit" id="submit" value="Submit" />

</body>
</html>

 

Yes, the JavaScript code is longer than what you'd get if you embedded it, but it's all in one centralized location, meaning it can be extracted into an external file you can use in multiple pages.  Not only that, but the JavaScript is completely separate from both the static markup and the markup generated by PHP, so it's easier to follow what the script is doing.  Now, obviously, in a contrived, just-off-the-top-of-my-head example like this, the benefits to this approach may not be very evident.  But there's a reason why the professionals stress developing in terms of tiers, and in using unobtrusive methods to render output.

 

Now, regarding the OP, it could be, as Skittalz said, that they need immediate results.  Fine.  But other forces will tug at the seams of the OP's application.  Good design application future-proofs projects from these forces.  So, maybe the band-aid will work here.  But as issues come up, and band-aids become harder and harder to integrate into the core application, they'll probably wish they took the time to properly design their site.  So, in the end, they'll be hit twice - once for all of the little tweaks and fixes that they employ, and once for finally biting the bullet and designing their app the right way, which they should've done at the beginning.

 

I don't mean to rant, but shrugging off the importance of application design when helping people who obviously need to rethink the direction of their project is the exact opposite of how we should help them.  If it's a matter of them being under a deadline...well, maybe they shouldn't have accepted a project from a paying client that's beyond their current skill level.

 

Just my $0.02.

Link to comment
Share on other sites

I have used header, but it makes problem like below:

 

I have given a condition to access header portion, but it does not work only for that condition.

Though the condition satisfy or not but page forward using header. Here is the code

 

$chk = $_POST["jschk"];

if ($chk != '1')

{

  header( 'Location: http://www.mydomain.net/mypage.htm' ) ;

}

 

Though the upper condition satisfy or not but page forwarded to mypage.htm page.

 

How I will solve this problem?

Link to comment
Share on other sites

I'm sorry, it was a little difficult to understand your English, so I may have misunderstood you, but I think that you want to change this:

 

if ($chk != '1')

 

to this:

 

if ($chk != 1)

 

In your code, you are checking for text that is '1'. But I think you want to check for a numeric value of one.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.