Jump to content

How can I create a delay in a php redirect?


abcdabcd

Recommended Posts

This is what my script looks like, the script is doing some other things such as appending a code to the url.  I don't know anything about php and had somebody create this script.  The only problem is that it's redirecting to fast and not appending the code every time. 

 

<? $xxxx = $_POST['xxxx']; header("Location: http://xxxx.com/xxxx?sub=$xxxx"); ?>

 

The coder had advised me:

 

Replace

header("Location: http://THE FINAL WEBSITE.COM"); ?>

 

With

<meta http-equiv="refresh" content="3;url=YOUR URL">

 

 

That's what I did and I got an "error on line 1"

Link to comment
Share on other sites

Sure, but you would have to start PHP again.  So probably easier to just echo it.

 

It's HTML

 

Either echo it or bring it out of PHP

 

echo "<meta http-equiv='refresh' content='3;url=YOUR URL'>";

 

 

If I bring it out of php, will the code that I'm appending to the url still work like that? 

Link to comment
Share on other sites

If the value is not available when the php code starts executing, it won't be present on the end of the URL. PHP code and PHP data is not asynchronous. External data either exists at the time the code starts or it does not exist. Putting a delay in the php code or in the redirect won't change anything. You need to find out why the value is not present and fix that issue or do it a different way.

 

My guess is that this value is an optional header that the browser supplies and the browser is simply not supplying it on the visit when it does not get appended to the URL.

Link to comment
Share on other sites

If the value is not available when the php code starts executing, it won't be present on the end of the URL. PHP code and PHP data is not asynchronous. External data either exists at the time the code starts or it does not exist. Putting a delay in the php code or in the redirect won't change anything. You need to find out why the value is not present and fix that issue or do it a different way.

 

My guess is that this value is an optional header that the browser supplies and the browser is simply not supplying it on the visit when it does not get appended to the URL.

 

I see what you're saying so I'm not going to put the delay in.  I'm not sure what the problem could be.  I'm getting the code from a form in html.  Here's the code being used on the 1st page.

 

<div id="apDiv2">Enter Code<br>

 

    <form name="formcode" id="formcode" method="post" action="http://xxxxx/code_forward.php">

    <input size="6" maxlength="3" value="" name="code" id="code" type="text">

</form>

 

After the user types in the code they are forwarded to a webpage on a different domain which is code_forward.php.

 

 

Then the code on here is:

 

<? $formcode = $_POST['formcode']; header("Location: http://xxxx.com/xxxx?sub=$formcode"); ?>

 

 

There is a possibility that my reporting could have messed up and didn't record the code.

 

With that line of code should it record it every time?  Does that look like a good effective way of accomplishing what I'm doing?

 

 

Thanks!  Any help would be appreciated!

 

Link to comment
Share on other sites

The name of the form field is "code" The post variable would be $_POST['code']

 

The name of the form field is "formcode" isn't it, below?

 

<form name="formcode" id="formcode" method="post" action="http://xxxxx/code_forward.php">

 

the line that you're referring which has "code" in it is referring to the name of the submit button correct?  Since it starts with, <input size=

 

It does work sometimes.

Link to comment
Share on other sites

I'm going to go ahead and try it out with the delay.  I remember having this problem doing the same exact thing with javascript, and when it was instant the code wouldn't append most of the time but, when I slowed it down to 3 seconds it worked every time. 

Link to comment
Share on other sites

Sure, but you would have to start PHP again.  So probably easier to just echo it.

 

It's HTML

 

Either echo it or bring it out of PHP

 

echo "<meta http-equiv='refresh' content='3;url=YOUR URL'>";

 

 

How can I bring it in/out of php, actually there is some HTML that I would like to add in here.  I need to add a loading animation.

 

 

Thanks!

 

If I bring it out of php, will the code that I'm appending to the url still work like that? 

Link to comment
Share on other sites

The name of the form field is "code" The post variable would be $_POST['code']

 

well that's strange, then how does it work sometimes?  I've seen the numbers in my reporting, I use the time of day to test with so I know I put the numbers in there for testing.

 

Anyway I just change anything called "code", to "formcode".

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.