473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Header redirect based on a GET variable does not work.

Hey I wrote the following jumpscript to perform some actions and jump to a new page but for some reason the page gets struck at this location and does not load the required url

Expand|Select|Wrap|Line Numbers
  1. <? 
  2.  
  3.   $getval = $_GET['redirect'];
  4.  
  5.   $str = "Location: ".$getval; 
  6.  
  7.   header('$str');
  8. ?>
  9.  
$getval has the valid URL but the header statement doesnt seem to work. Can anyone help me out plz?
Sep 26 '07 #1
6 2191
brettl
41
Try it without any spaces between your lines. See php.net/header .
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Sep 26 '07 #2
I tried ... did not help
Sep 26 '07 #3
nathj
938 Expert 512MB
Hey I wrote the following jumpscript to perform some actions and jump to a new page but for some reason the page gets struck at this location and does not load the required url


<?

$getval = $_GET['redirect'];

$str = "Location: ".$getval;

header('$str');
?>

$getval has the valid URL but the header statement doesnt seem to work. Can anyone help me out plz?
Hi,

Try the following code:
[php]
<?php
$lcTarget=$_GET['redirect'];
header("Location:$lcTarget");
?>
[/php]
I've done stuff like this before and it works a treat.

Hope this helps you out
nathj
Sep 27 '07 #4
garys
1
Take the single quotes out in the header call.

Expand|Select|Wrap|Line Numbers
  1. <? 
  2.  
  3. $getval = $_GET['redirect'];
  4.  
  5. $str = "Location: ".$getval; 
  6.  
  7. header($str);
  8. ?>
  9.  
Sep 28 '07 #5
Atli
5,058 Expert 4TB
Hi.

Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

Moderator

As for your problem.

The two previous posts will fix your problem, but they do not really explain it.
The reason it didn't work was because you used single-quotes around your $str variable. Single quotes will instruct PHP to print exactly what you put inside them, and not to evaluate any variable names within them.
Double quotes, however, will evaluate variable names and replace them with their values.
For example:
Expand|Select|Wrap|Line Numbers
  1. $str = "My string";
  2.  
  3. echo "$str"; # Prints: My string
  4. echo '$str'; # Prints: $str
  5.  
Sep 29 '07 #6
Ya it works fine now ....
and will surely put the code in [code] tags ...
thanx a lot for ur help
Oct 1 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nick Whitelegg | last post by:
Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication script which checks a username/password. If the...
10
by: Bob Garbados | last post by:
forgive my ignorance, as I'm new to php coming from a ms background... If I create a page named redirect.php and it's only content is: <?php header("Location: http://www.google.com"); ?>...
2
by: Marcus | last post by:
Hello, I am having problems with an include statement. I'm setting a session variable flag and then including a file, and in that include file I have a check at the top to make sure that the...
30
by: Anon | last post by:
If Http headers specify the character encoding, what is the point of the Meta tag specifying it?
1
by: MikeM | last post by:
We are getting a behavior on a Response.Redirect("SomeUrl", True) that I'm hoping someone can explain. This all refers to the code snip at the end. By the way, this is all VB ASP.NET v1.0 code. ...
3
by: maya | last post by:
yes I know, this has been asked many times, but I don't quite the answers: usu. answers are to put the redirect code -- in my case $URL =...
12
by: Jerim79 | last post by:
I have created a verification script to verify information and redirect the customer to the appropriate error page. For example: if ($FName=""){ header('Location:/verify_fname.htm'); } else{...
0
by: | last post by:
Hi here is the situation we have IIS site with multiple host headers based on host header we need to send to different URL's within the server my current solution (hate to call it naive :)...
8
by: pedalpete | last post by:
I thought this should be simple, but i can't seem to get it to work. I'm trying to do a simple redirect to a page, but need to pass a variable. I've tried a few things, but nothing seems to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.