Php header...

Posted on 2011-02-27
Medium Priority
Last Modified: 2012-05-11
Any ideas why it will not accept my variable as variable. It thinks it is a string value.

// The link is variable depending on the page.
$txnlink = http://www.google.com;

header('Refresh: 4; URL =$txnlink');

Open in new window

Question by:blink10
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
  • 2
LVL 16

Expert Comment

ID: 34990948
// The link is variable depending on the page.
$txnlink = "http://www.google.com";

header('Refresh: 4; URL =$txnlink');

Accepted Solution

LAMASE earned 2000 total points
ID: 34991019
You are using single quotes
header('Refresh: 4; URL =$txnlink');

Open in new window

for have the variable parsed you should use double quotes,
header("Refresh: 4; URL =$txnlink");

Open in new window

or string concatenation
header('Refresh: 4; URL ='.$txnlink);

Open in new window


Expert Comment

ID: 34991066
Ah, and you use quotes in the other string, too

$txnlink = "http://www.google.com";

Open in new window

LVL 111

Expert Comment

by:Ray Paseur
ID: 34991752
Here is the man page about string definitions.  You really want to read this and understand the syntax completely.

Here is the man page about the header() function. Whenever you are not 100% sure what a PHP function does, you can find the function documentation online.  Take note of the very common error about the use of header() after browser output has already occurred.  Even invisible whitespace can cause problems for your script.

It looks like you mean to cause the client browser to refresh and redirect to Google after 4 seconds.  You can do this, of course, but from a UX standpoint, I think I would ask myself if this is really a good thing for the client.  What will they see on the screen for 4 seconds?  Is 4 seconds a sensible length of time to display this information?  What can a client do with the information that will disappear after 4 seconds?  You might want to ask yourself, is it really necessary to display this at all?

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

771 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