Page 1 of 2
Using a variable in a header...
Posted: Tue Dec 09, 2008 5:32 am
by oscardog
I have the following code, i have honestly tried everything... just putting $page , putting speech marks around it.. putting ' around it.. putting the full URL.. not including Location, including Location.. just putting ' around the $page part... EVERYTHING. Nothing works, if alternatively you have another way of doing this, and its not terribly complex, feel free to suggest.
Code: Select all
<?php
$type = $_POST['type'];
$mode = $_POST['mode'];
$month = $_POST['month'];
if($type == "Planner" && $mode == "View") {
$page = "Location:view_planner.php?month=$month";
}
if($type == "Planner" && $mode == "Edit") {
$page = "Location:edit_planner.php?month=$month";
}
if($type == "Diary" && $mode == "View") {
$page = "Location:view_diary.php?month=$month";
}
if($type == "Diary" && $mode == "Edit") {
$page = "edit_diary.php?month=$month";
}
header("Location: http://www.ashpea1.exofire.net/$page");
?>
Thanks!
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 5:44 am
by papa
Have you checked that your post vars are set?
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 5:45 am
by mmj
You're having a problem sending get variables when redirecting with the location header?
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 6:57 am
by oscardog
Hmm well im pretty sure the post VARS are set, but i'll make sure. But yeh pretty sure, and basically it will take a month, from a form(aswell as type(planner/diary) and mode(edit/view). It will then redirect to the appropriate page, passing on the month taken from the form onto the page it redirects to.
ATM when i use the code pasted below it either puts in the URL ashpea1.exofire.net/Diary/$page or put in the URL with LOCATION before it... Or it will just be a white page, or wierdly occassionally will just remain on the page that the form is on :S
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 7:06 am
by papa
Do:
echo $type = $_POST['type'];
echo $mode = $_POST['mode'];
echo $month = $_POST['month'];
And maybe:
Code: Select all
header("Location: http://www.ashpea1.exofire.net/".$page);
But first make sure you have the vars set.
I would probably do a switch statement and have a default url to fall back on.
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 7:18 am
by novice4eva
is this some new cool code i dunno abt?? What is that "location:" string doing there??
Code: Select all
$page = "Location:view_planner.php?month=$month";
//SHOULDN'T THIS BE JUST
$page = "view_planner.php?month=".$month;
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 8:28 am
by mmj
novice4eva wrote:is this some new cool code i dunno abt?? What is that "location:" string doing there??
Code: Select all
$page = "Location:view_planner.php?month=$month";
//SHOULDN'T THIS BE JUST
$page = "view_planner.php?month=".$month;

, Location: Location
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 4:35 pm
by oscardog
Right i did the echo thing, all the variables are set correctly, using the header line you suggested Papa, it put in the URL bar:
http://www.ashpea1.exofire.net/Location ... th=January
So close, but no cigar... Its mostly right, just i dont want the location thing in there...
Removing location doesn't work it jsut leaves the page blank... Replacing the speech marks with ' doesnt work.. Stumped

I checked PHP.net its no help..
Re: Using a variable in a header...
Posted: Tue Dec 09, 2008 7:26 pm
by novice4eva
oscardog wrote:Right i did the echo thing, all the variables are set correctly, using the header line you suggested Papa, it put in the URL bar:
http://www.ashpea1.exofire.net/Location ... th=January
So close, but no cigar... Its mostly right, just i dont want the location thing in there...
Removing location doesn't work it jsut leaves the page blank... Replacing the speech marks with ' doesnt work.. Stumped

I checked PHP.net its no help..
all i get is 404 Error with some advertisement in it : with/without Location in the URL!!
Re: Using a variable in a header...
Posted: Wed Dec 10, 2008 3:56 am
by oscardog
OMG im such a retard! I forgot i had a a /Diary/PAGE WOW im retarded...
But it still leaves the 'Location' part in the URL, so...
Re: Using a variable in a header...
Posted: Wed Dec 10, 2008 4:14 am
by papa
Can you show us your updated code?
Re: Using a variable in a header...
Posted: Wed Dec 10, 2008 7:51 am
by oscardog
Code: Select all
<?php
$type = $_POST['type'];
$mode = $_POST['mode'];
$month = $_POST['month'];
if($type == "Planner" && $mode == "View") {
$page = "Location:view_planner.php?month=$month";
}
if($type == "Planner" && $mode == "Edit") {
$page = "Location:edit_planner.php?month=$month";
}
if($type == "Diary" && $mode == "View") {
$page = "Location:view_diary.php?month=$month";
}
if($type == "Diary" && $mode == "Edit") {
$page = "edit_diary.php?month=$month";
}
header("Location: http://www.ashpea1.exofire.net/Diary/$page");
?>
So i added in the missing directory, so the page now exists but ony when i manually remove the Location part from the URL...
13:53 GMT - Web Server is currently down, so dont try and access the website cos it will fail...
Re: Using a variable in a header...
Posted: Wed Dec 10, 2008 7:56 am
by papa
As novice4eva said earlier, no location: in the $page variable.
Re: Using a variable in a header...
Posted: Wed Dec 10, 2008 11:52 am
by oscardog
This is my new updated code, still not working... This time it just leaves a blank page? :S
Code: Select all
<?php
$type = $_POST['type'];
$mode = $_POST['mode'];
$year = $_POST['year'];
$month = $_POST['month'];
if($type == "Planner" && $mode == "View") {
$page = "view_planner.php?month=$month&year=$year";
}
if($type == "Planner" && $mode == "Edit") {
$page = "edit_planner.php?month=$month&year=$year";
}
if($type == "Diary" && $mode == "View") {
$page = "view_diary.php?month=$month&year=$year";
}
if($type == "Diary" && $mode == "Edit") {
$page = "edit_diary.php?month=$month&year=$year";
}
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/$page");
exit;
?>
I did add in an extra variable, the year, and added that into the $page variable. I removed "Location" from the header statement. Thanks
Edit: Updated with new code, so it works when i move from test server to proper server... Still no luck, although wierdly when i submit the data it just loads the page the form is on...
http://www.ashpea1.exofire.net/Diary/diarycentral.php - if you wnt to test it you have to make an account... And if i put echo statements in, to test the variables, they are all fine 100% and it loads diaryprocess.php which is really, really wierd..
And after checking php.net im 100% sure in need the "Location: " part in the header statement...
Re: Using a variable in a header...
Posted: Wed Dec 10, 2008 3:49 pm
by oscardog
Anyone?
