0

When people going to comment to my webpage, it will validate first if you are already login yet or not.

If not, then you have to log in first, what I try to doing here is that, after you log in. you will redirect to last page when you try to give a comment

So, I try to redirect page with GET method using PHP header("Location:");

This is my code:

HTML :

<form method="POST" action="addcomment.php">
    <textarea class="commentarea" name="comment" placeholder="your comment"></textarea>
    <input type="submit" name="submitcomment" value="Comment" />
</form>

addcomment.php :

header("Location:../loginfirst.php?location=".$_SERVER['HTTP_REFERER']);

it will send to loginfirst.php page, and the url will look like this :

http://localhost/ayojo/loginfirst.php?location=http://localhost/ayojo/product.php?p=test

After that, I try this code on loginfirst.php :

$_GET['location'] = $test;

    header('Location:'.$test);

Finally, I try log in then success. but, php header redirect me to the loginfirst.php not on the $_GET['location'].

What's wrong with my code?

1
  • how on earth your localhost/ayojo will work on other machines? Commented Jul 2, 2015 at 9:29

2 Answers 2

1

Shouldn't you declare the var $test as $_GET? So in loginfirst.php:

$test = $_GET['location'];

You've got it the other way around now.

Sign up to request clarification or add additional context in comments.

1 Comment

Aiken, thanks for answering. i try your method but still not working
0

Use urlencode while setting header and assign value of $_GET['location'] to $test.

addcomment.php :

header("Location:loginfirst.php?location=".urlencode($_SERVER['HTTP_REFERER']));

loginfirst.php :

$test = $_GET['location']; header('Location:'.$test);

2 Comments

thanks dhi_m for your answer, it still not working. after i login, i will redirect to the loginfirst.php not on the last comment page.
Are you checking session in other pages? if yes make sure that session is set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.