Jump to content

Redirect using special function


MushMX
Go to solution Solved by requinix,

Recommended Posts

Hi i need to perform an automatic redirect. sp when the page loads, automatically redirect to another one by using a special function:

?dashboard=user&page=member&tab=viewmember&action=view&member_id=<?php echo esc_attr($retrieved_data->ID);?>

 

but i dont know how can figure out this any ideas?

best regards :D

Link to comment
Share on other sites

11 minutes ago, requinix said:

Why load the first page at all if you're just going to redirect them immediately anyway?

Don't send them back to the first page. Send them directly to the second page instead.

requires member id and can only be retrieved from a page first, there's non a static link changes depending on the member id

Link to comment
Share on other sites

I mean

2 hours ago, MushMX said:

Hi i need to perform an automatic redirect. sp when the page loads, automatically redirect to another one by using a special function:

That page. The one you're talking about "when it loads".

I'm saying, don't load that page. Ones before it fine, but instead of "when the page loads I want them to redirect somewhere else" you should do "don't load that page and instead do the redirect at that moment".

If that's not making sense, and there's a good chance it doesn't, then please explain more about what "pages" you're talking about.

Link to comment
Share on other sites

Just now, requinix said:

I mean

That page. The one you're talking about "when it loads".

I'm saying, don't load that page. Ones before it fine, but instead of "when the page loads I want them to redirect somewhere else" you should do "don't load that page and instead do the redirect at that moment".

If that's not making sense, and there's a good chance it doesn't, then please explain more about what "pages" you're talking about.

Ill figure out with a javascript function (set on the properly site on the code in order to avoid a infinite loop)

This is the solution:

Hyper link class with ID name in order to we can call it with a function.
The original page loads, and retrieve the ID that we need.
Then wild script appears and "click" the link quickly, then load the page automatically performing the redirect
and that's all, many thanks  for the interest.

<a class="color_black" id="btn" href="?dashboard=user&page=member&tab=viewmember&action=view&member_id=<?php echo esc_attr($retrieved_data->ID)?>">
<script>
window.onload = function(){
  document.getElementById('btn').click();
}
</script>

Link to comment
Share on other sites

  • Solution

Okay yeah no, you're missing the point.

Look at this:

<a class="color_black" id="btn" href="?dashboard=user&page=member&tab=viewmember&action=view&member_id=<?php echo esc_attr($retrieved_data->ID)?>">

You know what URL you want the user to go to. After all, it's right there in the link.

So if you know what the URL is, why even bother having this page at all? Why give the user some HTML page when all you're going to do is trigger some Javascript that immediately sends them somewhere else? It's wasteful.

Instead of giving them this page, do the redirect.

In case you weren't aware, you can do it with some PHP code. Maybe that was the missing piece in this puzzle? It looks like this:

$url = "?dashboard=user&page=member&tab=viewmember&action=view&member_id=" . esc_attr($retrieved_data->ID);
header("Location: $url");

You execute that code before making any output at all. None at all. Then you stop executing after that - so no output after it either.

And that's how you do a redirect from within PHP. One that doesn't require any HTML or Javascript.

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.