Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 03:55 AM
Filth
Guest
 
Posts: n/a
Default help with variables in header location

Hi

this is probably very easy to sort but I want to do the following:-

header( "Location:
subscribe_form.php?name='.$_GET['name'].'&email='.$_GET['email'].'");

but this pulls up the error:-

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting
T_STRING or T_VARIABLE or T_NUM_STRING in
/home/httpd/vhosts/promotingmusic.co.uk/httpdocs/test/subscribe.php on line
11

the above being line 11. How would I go about encoding the URL properly. The
reason I am doing this is that I am using a form that is being validated via
another script and if there is a problem I wish to fiorward them back to the
form with it pre filled in.

Also is this the correct method for doing this.

Cheers in advance.





  #2  
Old July 17th, 2005, 03:55 AM
Cameron
Guest
 
Posts: n/a
Default Re: help with variables in header location

Filth wrote:[color=blue]
> Hi
>
> this is probably very easy to sort but I want to do the following:-
>
> header( "Location:
> subscribe_form.php?name='.$_GET['name'].'&email='.$_GET['email'].'");
>
> but this pulls up the error:-
>
> Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting
> T_STRING or T_VARIABLE or T_NUM_STRING in
> /home/httpd/vhosts/promotingmusic.co.uk/httpdocs/test/subscribe.php on line
> 11
>
> the above being line 11. How would I go about encoding the URL properly. The
> reason I am doing this is that I am using a form that is being validated via
> another script and if there is a problem I wish to fiorward them back to the
> form with it pre filled in.
>
> Also is this the correct method for doing this.
>
> Cheers in advance.
>
>[/color]

You aren't closing your quotes


header("Location: subscribe_form.php?name='" . _GET['name'] . "&email="
.....etc

~Cameron


  #3  
Old July 17th, 2005, 03:55 AM
Filth
Guest
 
Posts: n/a
Default Re: help with variables in header location

> > header( "Location:[color=blue][color=green]
> > subscribe_form.php?name='.$_GET['name'].'&email='.$_GET['email'].'");[/color][/color]
[color=blue][color=green]
> >
> > Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,[/color][/color]
expecting[color=blue][color=green]
> > T_STRING or T_VARIABLE or T_NUM_STRING in
> > /home/httpd/vhosts/promotingmusic.co.uk/httpdocs/test/subscribe.php on[/color][/color]
line[color=blue][color=green]
> > 11[/color]
>
> You aren't closing your quotes
>
>
> header("Location: subscribe_form.php?name='" . _GET['name'] . "&email="
> ....etc[/color]

Hi Cameron cheers for the quick response I notice in your example you missed
off the $ in the get variable was this meant or is it a typo (I presume it
was a typo) also I am presuming it is another type but you have closed a "
using a ' followed by a "

working on my presumptions I tried:-

header("Location: subscribe_form.php?name=" ". $_GET['name'] . '&email=' .
$_GET['email'] ." );

and

header("Location: subscribe_form.php?name=" ". $_GET['name'] ." '&email=' ".
$_GET['email'] ." );

which gave me the following error:-

Parse error: parse error, unexpected '\"' in
/home/httpd/vhosts/promotingmusic.co.uk/httpdocs/test/subscribe.php on line
11

Can you see what I am doing wrong?


  #4  
Old July 17th, 2005, 03:55 AM
Shawn Wilson
Guest
 
Posts: n/a
Default Re: help with variables in header location

Filth wrote:[color=blue]
>
> Hi
>
> this is probably very easy to sort but I want to do the following:-
>
> header( "Location:
> subscribe_form.php?name='.$_GET['name'].'&email='.$_GET['email'].'");
>
> but this pulls up the error:-
>
> Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting
> T_STRING or T_VARIABLE or T_NUM_STRING in
> /home/httpd/vhosts/promotingmusic.co.uk/httpdocs/test/subscribe.php on line
> 11
>
> the above being line 11. How would I go about encoding the URL properly. The
> reason I am doing this is that I am using a form that is being validated via
> another script and if there is a problem I wish to fiorward them back to the
> form with it pre filled in.[/color]

A few problems:

Always url_encode your variables when they're in a header. Otherwise, if you
have a space or another invalid character you'll get an error.
You should use absolute URLs in the location header. Some browsers do not
support relative URLs.
Single and double quotes aren't interchangable (I assume you don't want single
quotes in the email and name variables).
Always close your quotes.

header( "Location:
http://yourdomain.com/script.php?name=".url_encode($_GET['name'])."&email=".urlencode($_GET['email']));

Regards,
Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
  #5  
Old July 17th, 2005, 03:55 AM
Filth
Guest
 
Posts: n/a
Default Re: help with variables in header location

> header( "Location:[color=blue]
>[/color]
http://yourdomain.com/script.php?name=".url_encode($_GET['name'])."&email=".urlencode($_GET['email']));

Thank you it worked perfectly except for the _ in the first urlencode.

Just so that I know for future reference why does the first get variable
have a . on either side but the second only has 1.

Regarding the urlencode not being there I was thinking wether I should be
doing that before infact I was looking at using rawurlencode() but wanted to
get it working first before I started with that

Cheers again

Peter


  #6  
Old July 17th, 2005, 03:55 AM
Shawn Wilson
Guest
 
Posts: n/a
Default Re: help with variables in header location

Filth wrote:[color=blue]
>[color=green]
> > header( "Location:
> >[/color]
> http://yourdomain.com/script.php?name=".url_encode($_GET['name'])."&email=".urlencode($_GET['email']));
>
> Thank you it worked perfectly except for the _ in the first urlencode.
>
> Just so that I know for future reference why does the first get variable
> have a . on either side but the second only has 1.
>
> Regarding the urlencode not being there I was thinking wether I should be
> doing that before infact I was looking at using rawurlencode() but wanted to
> get it working first before I started with that[/color]

Whoops. My mistake with the underscore.

The "." means append, add or join. If you had more stuff to tack on the end it
would be:

blah...blah...blah...email=".urlencode($_GET['email'])."&foo=bar");

But since you didn't, you did not need the dot.

$string = "A"."B"."C"; //$string is "ABC"
$string = "A"."B"; //$string is "AB"
$string = "A"."B".""; //$string is "AB". Extra dot is not needed

Regards,
Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
  #7  
Old July 17th, 2005, 03:55 AM
Filth
Guest
 
Posts: n/a
Default Re: help with variables in header location

> The "." means append, add or join. If you had more stuff to tack on the
end it[color=blue]
> would be:
>
> blah...blah...blah...email=".urlencode($_GET['email'])."&foo=bar");
>
> But since you didn't, you did not need the dot.
>
> $string = "A"."B"."C"; //$string is "ABC"
> $string = "A"."B"; //$string is "AB"
> $string = "A"."B".""; //$string is "AB". Extra dot is not needed[/color]

Ahh brilliant explanation I now understand completely CHEERS :>

Peter


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.