doubledee — 2011-08-23T22:40:05-04:00 — #1
I think I am confused about GETs, POSTs, and Redirects.
What causes a GET to come into existence?
What causes a POST to come into existence?
When you "Redirect", what is that?
cranial_bore — 2011-08-23T23:09:16-04:00 — #2
GET and POST are types of HTTP requests. The client (e.g. browser) will send the request to the server which can include GET/POST values
GET will come from a query string in the URL.
$_GET['something'] will be 'value';
POST occurs most often when the user has submitted a form, and it had a method of POST. The URL won't show a change as with GET, but the data will be sent as part of the request.
<form method="post" action="script.php">
<input type='text' name='something' value='value'>
$_POST['something'] will be 'value';
POST can be sent without a form.
There are different types of redirect. Typically the server will send a HTTP header to the user agent which has a redirect instruction, or a status code indicating the resource has moved.
Browsers will redirect in this case, but if you depend on your script end you must also call exit() because you can't trust them to redirect. It's just an instruction.
doubledee — 2011-08-23T23:15:20-04:00 — #3
Why is it that when I did a redirect with a "pretty URL" that there wasn't a GET involve?
My "pretty URL" is supposed to be converted to a Query String and so based on what you said I'd expect GET to have a value...
doubledee — 2011-08-23T23:32:48-04:00 — #4
In "article.php" I set my page to return back to...
// Set Article Title.
$articleTitle = $_GET['title'];
$_SESSION['articleTitle'] = $_GET['title'];
// Set current Script Name + Query String.
$_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME'] . '/' . $articleTitle;
And then after the user successfully logs in on "log_in2.php" my code is supposed to bring them back to the specific article they were reading on "article.php"...
// Redirect User.
header("Location: " . $_SESSION['returnToPage']);
// Take user to Home Page.
header("Location: " . WEB_ROOT . "index.php");
// End script.
But if I have a returnToPath = '/article.php/postage-meters-save-you-money then why isn't it working and creating a GET value?
cranial_bore — 2011-08-24T00:06:23-04:00 — #5
Do you have a rewrite rule (.htaccess) to convert article.php/title into article.php?title=$title
If not, then having article.php/something won't create a GET variable. You need the ? in there.
doubledee — 2011-08-24T00:08:43-04:00 — #6
RewriteRule articles/([a-zA-Z0-9_-]+)$ article.php?title=$1
cranial_bore — 2011-08-24T00:22:11-04:00 — #7
Try this (escaping - so it doesn't get confused as part of a character range)
RewriteRule articles/([a-zA-Z0-9_\\-]+)$ article.php?title=$1
Does manually requesting articles/postage-meters-can-save-you-money work?
doubledee — 2011-08-24T00:27:24-04:00 — #8
My mod_rewrite works just fine on its own.
Redirecting from "log_in2.php" back to "/articles/postage-meters-can-save-you-money" is the issue.
cranial_bore — 2011-08-24T01:31:04-04:00 — #9
The header function is supposed to get a full absolute URL, but normally browsers can cope with a relative one. Have to echoed $_SESSION['returnToPage'] to see that the value is what you expect?
system — 2011-08-24T01:41:11-04:00 — #10
Starting to be reminded of why I redirect EVERYTHING that isn't a static file at a single index.php, then manually parse $SERVER['REQUESTURI'] instead.
Which would be my advice on it. Pathinfo, then explode on /.
doubledee — 2011-08-24T21:18:05-04:00 — #11
What is the best way to achieve that?
Sounds like a need for my config.inc.php file which goes like...
// File Root
define('ROOT', ENVIRONMENT === 'development'
// Web Server Root
define('WEB_ROOT', ENVIRONMENT === 'development'
Would that work?
starlion — 2011-08-24T22:40:27-04:00 — #12
Slight note - there is an HTTP GET, and PHP's $_GET. HTTP GET is a HTTP Verb (Protocol Method), used to describe the transaction desired with a message sent to a web server. GET is used to tell the webserver "I want the following resource.". POST is likewise, but specifies to the server that there is data being passed.
A Redirect is an HTML construct as well - in response to the HTTP GET/POST, the server (whether prompted by PHP, or apache, or whatever) responds with one of a couple of status numbers that indicate the URL has been redirected (Any status code in the 300 range is classified as a Redirect)
PHP's $GET and $POST are superglobal variables that always 'exist', but are empty unless there are variables passed in the query-string section of a URL (for $GET), or in the message section of a POST operation ($POST). It is perfectly possible to pass both at the same time (Send a POST operation, aimed at a URL the contains query string variables)[/OT]