Skip to content
Advertisement

Login redirect Issue in post comment area in PHP

If someone wishes to comment on any item e.g. and article or forum item, etc. on my site. It prompts them to login/create account. Is it possible to make sure that when the client logs in it takes them back to the comment they wanted to make?

But now it’s going not like this flow. The user not logging in redirects to the login page, but I want, after logging in to this section, the user is automatically redirected to the current post comment area. Is there a way?

<?php if ($sessionUser == 1 || $sessionSeller == 1 || $sessionadmin == 1) { ?>

    <form class="cp_form"
          action="article_comments_db.php"
          method="post"
          name="frm_comment"
          id="frm_comment">

        <div id="div_req_comment" class="cp_infopanel_off">
            <span><?= $_Reviews ?></span>:<span class="red">*</span>

            <textarea class="cp_textarea"
                      id="req_comment"
                      name="req_comment"
                      onBlur="do_blur(this.id)"
                      onFocus="do_focus(this.id)"></textarea>

            <div id="infobox_req_comment" class="cp_infobox"></div>
        </div>

        <input type="button"
               id="btn_submit"
               class="rp_button"
               value="<?= $_Submit ?>"
               onClick="validate_form('frm_comment')" />

        <input type="hidden"
               name="id" value="<?php echo $id ?>" />
    </form>

<?php } else {
?>

    <br/><br/>
    <div align="right">

        <input type="button"
               id="btn_submit"
               class="rp_button"
               value=" <?= $_Post_comment ?> "
               onClick="window.location.href='login.php?event=Account'" />
    </div>

<?php
}

Advertisement

Answer

You could call your login.php?event=Account with an ID or the URL (urlencode) of the current page visited by the user.

login.php?event=Account&visitedpageid=1

In the loginform you could fetch the ID/URL with $_GET and put it in a hidden input.

<input type="hidden" name="visitedpage" value="<?php echo $_GET['visitedpageid']; ?>">

If login was correct, you then redirect by using the POST-value of that hidden input.

$_POST['visitedpage']

Please make sure you check if the get-parameter is set (isset) and matches to an existing page.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement