Quick php question about URLs
Discussion
I'm passing information back to the server user URL encoding, the parameters passed back are determined in the page in the HREF.
One of the paramters indicates the action that the script needs to take, in my case 'start' or 'stop' a server side process. But it could be anything like adding or removing a user.
The problem that I have is that when the page contents are returned back to the browser the URL in the address bar still contains the previous action.
This means if the user rereshes the page (F5) the action gets repeated, which could cause an error.
Is there anyway to 'reset' the URL in the browser's address bar from within PHP or do I need to move to using Forms and $_POST instead of $_GET.
Thanks.
One of the paramters indicates the action that the script needs to take, in my case 'start' or 'stop' a server side process. But it could be anything like adding or removing a user.
The problem that I have is that when the page contents are returned back to the browser the URL in the address bar still contains the previous action.
This means if the user rereshes the page (F5) the action gets repeated, which could cause an error.
Is there anyway to 'reset' the URL in the browser's address bar from within PHP or do I need to move to using Forms and $_POST instead of $_GET.
Thanks.
Have the submit action exit to a results page that displays the results of the last insert property?
$query_LastInsertedRecordset = "SELECT LAST_INSERT_ID() AS LastID";
$LastInsertedRecordset = mysql_query($query_LastInsertedRecordset, $trlink) or die(mysql_error());
$row_LastInsertedRecordset = mysql_fetch_assoc($LastInsertedRecordset);
$totalRows_LastInsertedRecordset = mysql_num_rows($LastInsertedRecordset);
Rob...That's not what I'm trying to achieve

The dark blue words are clickies, and the script action is URL encoded, you can see in the address bar that I've just clicked the 'start' anchor/clicky for Site 1.
However, seems likely that to me the user will click Refresh of press F5 to check the status at a later date, that screws up as the Browser spits back the action=start&id=1&sel=1 again and the RCS process gets restarted.
If I could change the URL in the Broswer address bar after the page has been returned, that will save me embedding lots of mini forms into the page to get the paramters back via $_POST.
The Griffalo said:
think they're just doing changes in the a $ variable.I wonder, can java script write to the browser address bar. though I guess that is probably verboten.
ETA... yep VERBOTEN... too easy for fishing.
Thinking I'm gonna have to use form elements


Edited by mystomachehurts on Thursday 26th July 17:28
You could use the php session to record that the action had taken place, then if the variable is present in the URL, only take action if the php session variable is false, ie
if ($_GET['action'] == 'whatever' && !$_SESSION['action']) {
// carry out the action
}
if ($_GET['action'] == 'whatever' && !$_SESSION['action']) {
// carry out the action
}
Edited by jagnet on Thursday 26th July 17:32
jagnet said:
You could use the php session to record that the action had taken place, then if the variable is present in the URL, only take action if the php session variable is false, ie
if ($_GET['action'] == 'whatever' && !$_SESSION['action']) {
// carry out the action
}
Yeah, I was thinking about doing that during dinner, it might work. I'd have to also track the outcome of the last action. So for example, if the user clicked start and the action worked, and then I saw the same action again just ignore it. But say there was an error and the start failed, then likely if I saw a start request again it would be likely to be a genuine request.if ($_GET['action'] == 'whatever' && !$_SESSION['action']) {
// carry out the action
}
Edited by jagnet on Thursday 26th July 17:32
Thanks for your thoughts!
So you click the link which calls another php script which does the processing, which then displays the page again?
In Java, you achieve this by either including the final page in the response, or redirecting to it.
If you include the page, the URL in the browser will be the one of the link you clicked on (with all of the parameters etc...) but if you redirect, it will be the URL of the page you're redirecting to. Is there something similar to this in PHP?
In Java, you achieve this by either including the final page in the response, or redirecting to it.
If you include the page, the URL in the browser will be the one of the link you clicked on (with all of the parameters etc...) but if you redirect, it will be the URL of the page you're redirecting to. Is there something similar to this in PHP?
SlidingSideways said:
So you click the link which calls another php script which does the processing, which then displays the page again?
In Java, you achieve this by either including the final page in the response, or redirecting to it.
If you include the page, the URL in the browser will be the one of the link you clicked on (with all of the parameters etc...) but if you redirect, it will be the URL of the page you're redirecting to. Is there something similar to this in PHP?
Yes, you can redirect in php using the header() function:In Java, you achieve this by either including the final page in the response, or redirecting to it.
If you include the page, the URL in the browser will be the one of the link you clicked on (with all of the parameters etc...) but if you redirect, it will be the URL of the page you're redirecting to. Is there something similar to this in PHP?
header ("Location: $newUrl");Edited by jagnet on Friday 27th July 09:57
jagnet said:
SlidingSideways said:
So you click the link which calls another php script which does the processing, which then displays the page again?
In Java, you achieve this by either including the final page in the response, or redirecting to it.
If you include the page, the URL in the browser will be the one of the link you clicked on (with all of the parameters etc...) but if you redirect, it will be the URL of the page you're redirecting to. Is there something similar to this in PHP?
Yes, you can redirect in php using the header() function:In Java, you achieve this by either including the final page in the response, or redirecting to it.
If you include the page, the URL in the browser will be the one of the link you clicked on (with all of the parameters etc...) but if you redirect, it will be the URL of the page you're redirecting to. Is there something similar to this in PHP?
header ("Location: $newUrl");Edited by jagnet on Friday 27th July 09:57
if($redirect_after_action == true)
{
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'site_management.php?action=view&sel=' . $_SESSION['selected_site'] ;
header("Location: http://$host$uri/$extra" ) ;
exit;
}
Many thanks everyone!
Once last little mod that other might want to bear in mind
When the script is processing a 'real' action i.e. before the user is redirected to a 'view' action, there may have been errors, warnings or notices generated by the script.
I usually store these in an array as the script is processing and then only output them right at the end. Trouble is as soon a the page redirects to and detects that it now a 'view' and not an 'action' these messages in the array are lost.
So, cunningly, once I know I am about to redirect I copy all the current errors into the session. I changed the redirect url to have an extra paramter that means the script now knows it is running because of a redirect and immediately copy all the $_SESSION stored errors/messages back into the script $errors array.
Of course, once the redirected 'view' script finishes processing it writes all the errors/warnings & messages from the previous 'action' page. Shweet.
Gotta love PHP, I am really down on procedural languages now after years of OO Java and some of these php scripts are approaching 1000s lines long and becoming a nightmare to maintain. But once you finally find the solution it's very satifying to see it all working.
Good stuff!
When the script is processing a 'real' action i.e. before the user is redirected to a 'view' action, there may have been errors, warnings or notices generated by the script.
I usually store these in an array as the script is processing and then only output them right at the end. Trouble is as soon a the page redirects to and detects that it now a 'view' and not an 'action' these messages in the array are lost.
So, cunningly, once I know I am about to redirect I copy all the current errors into the session. I changed the redirect url to have an extra paramter that means the script now knows it is running because of a redirect and immediately copy all the $_SESSION stored errors/messages back into the script $errors array.
Of course, once the redirected 'view' script finishes processing it writes all the errors/warnings & messages from the previous 'action' page. Shweet.
Gotta love PHP, I am really down on procedural languages now after years of OO Java and some of these php scripts are approaching 1000s lines long and becoming a nightmare to maintain. But once you finally find the solution it's very satifying to see it all working.
Good stuff!
zoidberg said:
You could try doing it with Ajax? Click the button, processing happens in the background, browser refreshes.
Have to say that I'm a BIG BIG fan of AJAX.It sits very comfortably with my design methodology. I'm self taught at programming, never studied at college or University, just read lots of books and lots of open source code.
What I find with AJAX is that it separates the layout and the processing very very cleanly. This is not something that I could say is easily achieved with PHP.
I'm not a GUI/layout man, I'm a programmer. I want to leave the layout to someone with a better eye and understanding for usability whilst I concentrate on the getting the behind the scenes stuff working.
With AJAX I can get someone else to layout the page, and then I can put the content into the DIVs using AJAX and PHP. It's a lovely solution and it makes your code very modular. It's only something I discovered halfway through developing this project, and I'd like to see the whole systm written this way.
However, alot of the code is now using AJAX for auto refreshing parts of the screen, submitting info back to the DB but my fear (and likely my inexperience) is with race conditions where AJAX is doing something and then the user clicks something else and the two get tied in knots.
I'm still dreaming on this one, I guess it may be a case of queing the actions somehow? I've done this alot in OO Java where my GUI classes are always separate to my processing classes and requests from the GUI are submitted into the processing class' queues. Updates to the GUI from the processing classes are submitted back into the GUI's queues. (Can you tell I like a lot of threads hanging about in wait states!)
I've not found a simple solution for this in AJAX yet.
ETA: That didn't sound too much like Twincam talking did it? Does he even ever come in here?
Edited by mystomachehurts on Friday 27th July 22:43
mystomachehurts said:
zoidberg said:
You could try doing it with Ajax? Click the button, processing happens in the background, browser refreshes.
Have to say that I'm a BIG BIG fan of AJAX.It sits very comfortably with my design methodology. I'm self taught at programming, never studied at college or University, just read lots of books and lots of open source code.
What I find with AJAX is that it separates the layout and the processing very very cleanly. This is not something that I could say is easily achieved with PHP.
I'm not a GUI/layout man, I'm a programmer. I want to leave the layout to someone with a better eye and understanding for usability whilst I concentrate on the getting the behind the scenes stuff working.
With AJAX I can get someone else to layout the page, and then I can put the content into the DIVs using AJAX and PHP. It's a lovely solution and it makes your code very modular. It's only something I discovered halfway through developing this project, and I'd like to see the whole systm written this way.
However, alot of the code is now using AJAX for auto refreshing parts of the screen, submitting info back to the DB but my fear (and likely my inexperience) is with race conditions where AJAX is doing something and then the user clicks something else and the two get tied in knots.
I'm still dreaming on this one, I guess it may be a case of queing the actions somehow? I've done this alot in OO Java where my GUI classes are always separate to my processing classes and requests from the GUI are submitted into the processing class' queues. Updates to the GUI from the processing classes are submitted back into the GUI's queues. (Can you tell I like a lot of threads hanging about in wait states!)
I've not found a simple solution for this in AJAX yet.
ETA: That didn't sound too much like Twincam talking did it? Does he even ever come in here?
Edited by mystomachehurts on Friday 27th July 22:43
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff



