| Coding Forum Problems with your code? Let's hear about it. |
06-11-2004, 11:57 AM
|
#1 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Pffffft
Posts: 8,857
Latest Blog: None
|
PHP Redirect
What code should be used to redirect to the last visited page? (Coding is in php)
|
|
|
06-11-2004, 11:59 AM
|
#2 (permalink)
|
|
No Longer Here
Join Date: 09-27-03
Location: State College, PA
Posts: 9,354
Latest Blog: None
|
What do you mean by the last visited page? What exactly are you trying to do?
|
|
|
06-11-2004, 12:01 PM
|
#3 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Pffffft
Posts: 8,857
Latest Blog: None
|
Like for a rating system... I want the page after you voted to redirect back to the review you just looked at after about 5-10 seconds. So you press Rate! on a review, it takes you to a confirmation page, then that redirects to the review you were looking at before you rated for it...
|
|
|
06-11-2004, 12:08 PM
|
#4 (permalink)
|
|
Possible Terrorist
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
|
well just use
<?php Header("Location: http://www.must-have-software.net/ratings.php?id=" . $id); ?>
You must have the id somewhere of where you rated it right?
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
|
|
|
06-11-2004, 12:11 PM
|
#5 (permalink)
|
|
v7n Mentor
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,940
|
You could use $referer = $_SERVER['HTTP_REFERER']; to store the referring page and then redirect to it.
This can also be done with JavaScript using the history code.
|
|
|
06-11-2004, 02:37 PM
|
#6 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Pffffft
Posts: 8,857
Latest Blog: None
|
.php?id=29
That's how it ends (29 is just an example one)
Which one is easier, Spears way or imaginemn's way? I've see imaginemn's way a lot of places...
|
|
|
06-11-2004, 04:39 PM
|
#7 (permalink)
|
|
v7n Mentor
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,940
|
I personally don't think one is better than the other. Both ways should work about the same way. The only difference I can see is that if you are already calling the $id then that's probably the easier of the two because you don't have to call an additional server resource. The only time this would ever come into play is if you are getting millions a hit a day and your server cannot keep up.
Both are a good way to solve your issue.
imaginemn
|
|
|
06-11-2004, 05:16 PM
|
#8 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Pffffft
Posts: 8,857
Latest Blog: None
|
Thanks. Would I put it exactly how theSpear has it now?
|
|
|
06-12-2004, 07:49 AM
|
#9 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: Lebanon
Posts: 4,099
Latest Blog: None
|
HTML:
[code:1:5648d0859e]
<input type="button" value="Back" onclick="history.back()">
[/code:1:5648d0859e]
|
|
|
06-12-2004, 11:29 AM
|
#10 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Pffffft
Posts: 8,857
Latest Blog: None
|
Samer, I need it to redirect back automatically, What you have inserts a button right?
|
|
|
06-12-2004, 12:31 PM
|
#11 (permalink)
|
|
v7n Mentor
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,940
|
Here is the code for my solution.
[code:1:0827f7fc84]<?php
// ----------------------------------------------------
// refresh / redirect to an internal page using Referer
// imaginemn solution
// ----------------------------------------------------
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 5; url='.$ref);
echo "You will be redirected to $ref in 5 seconds";
?>[/code:1:0827f7fc84]
OR
[code:1:0827f7fc84]<?php
// --------------------------------------------------------------
// refresh / redirect to an internal page using existing variable
// theSpear solution
// --------------------------------------------------------------
header( 'refresh: 5; url=ratings.php?id='.$id);
echo "You will be redirected to ratings.php?id='.$id in 5 seconds";
?>[/code:1:0827f7fc84]
imaginemn
|
|
|
06-14-2004, 09:56 AM
|
#12 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Pffffft
Posts: 8,857
Latest Blog: None
|
The first one looks like it'll do. Thanks imaginemn. Does the $ref mean the referring page?
|
|
|
06-14-2004, 10:28 AM
|
#13 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: Lebanon
Posts: 4,099
Latest Blog: None
|
Quote:
|
Samer, I need it to redirect back automatically, What you have inserts a button right?
|
yep, sorry.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 08:36 PM.
© Copyright 2008 V7 Inc
|