Jump to content

Passing a URL?


doubledee

Recommended Posts

can you show a little of the infrastructure of your code so I have an idea as to what exactly your logic is

 

I'm not sure I want to do what I'm asking help for now?!

 

Here is the problem I want to solve...

 

A visitor is on Page-1 and wants to do something that requires logging in.

 

I need to capture what and where Page-1 is at, so that after they register, get an account activation e-mail, click on that link, and get a log-in screen, they will then be transferred back to Page-1 so they can pick up where they left off.

 

I am thinking maybe I can just store Page-1 in a $_SESSION and then refer to that later?!  :shrug:

 

 

 

Debbie

 

 

Link to comment
Share on other sites

however if you want to do it your way, there might be a way to set a session with the value of $_SERVER['SCRIPT_NAME'] and have it update each time the user jumps to a page that isn't your login page, then when the user needs to login, call the session value that should contain the last page that the user visited...

Link to comment
Share on other sites

$_SERVER['HTTP_REFERRER'] will tell you the URL that you came from.  Just make sure you validate it.

 

I tried that function but it doesn't work.  I get the error:

 

Notice: Undefined index: HTTP_REFERRER in /Users/user1/Documents/DEV/++htdocs/01_MyProject/create_account.php on line 140

 

From what I Googled, it sounds like this function is unreliable.

 

Is there something that does the same thing but which is more reliable?!

 

Thanks,

 

 

Debbie

 

 

Link to comment
Share on other sites

Why not just have the form action say.. http://site.com/signup.php?gotoafter=currentlink

then when you are done signing up, have it redirect you to $_GET['goafter']

 

EDIT: oops.. the link to signup should be contain the current url and then when you click on it it will send that data to the signup page, from there you can redirect back.

Link to comment
Share on other sites

It's misspelled. It's $_SERVER['HTTP_REFERER'].

 

I made one step forward but am still having issues re-directing to the original page after logging in.

 

Here is the sequence of events...

 

- Visitor is on "original_page.php"

- Visitor clicks "Add a Comment"

- System displays a message to "Log In" or "Create an Account"

- Visitor chooses "Create an Account"

- System displays a "Create an Account" form

- Visitor enters Name, Email, and Password

- System confirms data

- System display a message saying it will send an Activation Link in an e-mail

- System sends e-mail

- Visitor opens e-mail and clicks on link

- Visitor is taken to "activate.php"

- System reads E-mail and Activation Code in link and activates account

- System displays message for user to click link to "Log In"

- Member clicks on link

- System displays "Log In" form ("log_in.php")

- Member logs in

- System reads $_SESSION['referringPage'] and *should* redirect to "original_page.php"

 

 

In "create_account.php" I have...

$_SESSION['referringPage'] = $_SERVER['HTTP_REFERER'];

 

 

And in "log_in.php" I have...

// Check for Member Record.
if (mysqli_stmt_num_rows($stmt)==1){
// Member was Found.

// Bind result variables.
mysqli_stmt_bind_result($stmt, $memberEmail, $memberFirstName);

// Fetch record.
mysqli_stmt_fetch($stmt);

$_SESSION['loggedIn'] = TRUE;
$_SESSION['memberEmail'] = $memberEmail;
$_SESSION['memberFirstName'] = $memberFirstName;

header("Location: " . $_SESSION['referringPage']);

// Send and turn off output buffering.
ob_end_flush();

// End script.
exit();

 

 

When I go to log in I get this error...

Notice: Undefined index: referringPage in /Users/user1/Documents/DEV/++htdocs/01_MyProject/log_in.php on line 114

 

 

Any idea what is going wrong??

 

Thanks,

 

 

 

Debbie

 

 

 

Link to comment
Share on other sites

Your session isn't getting set. You really should first verify that your server provides this server value.

 

I accidentally CUT my session code instead of COPYING it to another page?!  Oops!!  :shy:

 

So what do you think about my process flow?

 

It seems like I have things working, but I'm still not sure how it works and appears to users?!

 

 

Debbie

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.