Reputation: 11
Hello guys how are you doing?
I'm working on a project using PDO statements, and I want to redirect the user to a certain URL where it brings it from the DB, but the browser gives me an error while redirecting.. and if I type a certain website into my code it redirects without any problem.
Here is my code:
if (isset($_GET['r']) || !empty($_GET['r']))
{
$l_url = $_GET['r'];
$con = $db->prepare("INSERT INTO links (url) VALUE (?)");
$con->execute(array($_POST['url']));
header("location:" .$l_url);
exit();
}
if I type any URL after "location" it'll redirect without any problems, but not with this here.
Error:
Firefox - "The page isn’t redirecting properly" in Firefox and " This page isn’t working, localhost redirected you too many times." in Chrome and I did clear the session & Cookies
Thank you.
Upvotes: 0
Views: 484
Reputation: 66
isset($_GET['r']) || !empty($_GET['r'])
Unnecessary code, you can change the above expression to the following:
!empty($_GET['r'])
About your question:
but the browser gives me an error while redirecting..
What error message are you receiving? Without this information I cannot help, but probably variable $_POST['url']
does not exist.
Upvotes: 1