Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP>> header("Location : my_file.php?submit=1#anchor");

Posted on 2004-10-25
13
Medium Priority
?
1,636 Views
Last Modified: 2012-08-13
Hello everyone

How do I redirect in PHP, using header();?? The thing is I am trying to redirect to an anchor of a page.

here the header();

header("Location : my_file.php?submit=1#anchor");

The "#" seems to be causing problems.

Thanks :)
0
Comment
Question by:minichicken
[X]
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
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 2

Expert Comment

by:suresh_asp
ID: 12408232
Try this

header("Location : my_file.php?submit=".htmlentities(urlencode("1#anchor")));
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12408246
AFAIK when using Location the # is not allowed (only absolute URIs should be used)

if you want to use an anchor you might do it via a meta-refresh tag. There the anchor is allowed.

0
 
LVL 12

Author Comment

by:minichicken
ID: 12408366
Hi

Thanks for your responses.

suresh_asp >> yours didnt work :(

hernst42 >> can you please show me how do i do that with meta-refresh.

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Accepted Solution

by:
hernst42 earned 400 total points
ID: 12408574
You can try this:

instead of header(..) :

?>
<html><head>
<meta http-equiv="refresh" content="1;url=my_file.php?submit=1#anchor" />
</head>
</html>
<?php
die(1);
0
 
LVL 3

Expert Comment

by:Boris Aranovich
ID: 12408735
why not  content="0;url=my_file.php?submit=1#anchor" (notice the 0 instead of 1)?
0
 
LVL 3

Expert Comment

by:Boris Aranovich
ID: 12408743
By the way, WHAT problems is the header() redirection causing with the # ?
0
 
LVL 12

Author Comment

by:minichicken
ID: 12408772
if i use header(); with # to point to the anchor on another page, it won't work..... i mean it doesnt redirect at all....
0
 
LVL 2

Assisted Solution

by:suresh_asp
suresh_asp earned 200 total points
ID: 12408781
Check this now
I got it
There shouln't be space after location

header("Location:my_file.php?submit=".htmlentities(urlencode("1#anchor")));
0
 
LVL 3

Assisted Solution

by:Boris Aranovich
Boris Aranovich earned 200 total points
ID: 12408795
Oh... Well, it can be due to the fact that the anchor is really client-sided thingie, and not the part of the URL for the server. Though, IMHO, it should work...
Use either what hernst42 said, or something like this:

<script>location='myfile.php?submit=1#anchor';</script>

Q: Is the redirection is really to the SAME page (just supposed to jump to the anchor), or a different page with some anchor?
0
 
LVL 3

Expert Comment

by:Boris Aranovich
ID: 12408803
suresh_asp, There SHOULD be a space.
Headers are formatter in this manner:

Headername: the_value_of_it\n
SomeOtherHeader: another_value\n
\n
<html>......
0
 
LVL 12

Author Comment

by:minichicken
ID: 12408807
it should redirect to a different page and jump to that anchor position... So it not on the same page....
0
 
LVL 3

Expert Comment

by:Boris Aranovich
ID: 12408828
Well, then, as I said, either try with hernst42's <meta refresh> or with javascript location='...'
0
 
LVL 12

Author Comment

by:minichicken
ID: 12408888
Thank you all for your inputs.

It was not the # anchor problem, it the max exec time problem, so i increased it to 5 min and it works fine now.
I try to send out 3 emails on that page, so it takes a bit of time.

Some feedback:

suresh_asp  >> The space after location does not make a difference.
hernst42 >> header(); does support # anchors, your provided solution should work (meta refresh)
Nomaed >> You provided solution should work (javascript redirect)

Thanks :)
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

618 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