this is a little bit tricky.
usually when someone clicks on a link that requires him to register, this person will be redirected to the registration page and then back to the last visited page. this is possible cause the link sent a GET key through the url to the registration.php which uses the key to go back to last visited page.
but i intend to use jquery ajax for registration. basically ive got 3 different php pages. all of them include the same header.php. and in header.php ive got a registration button which i have id tagged. when this button is clicked ( $(#registration_button).click()... ) jquery will show a box (a div that was hidden in the center of the browser) with registration information. then he will register and i will redirect him to the last visited page, that is to say the current one he sees. i have to refresh the php-page to be able to show all links that a registered user can see, thats why i have to use window.location.href.
now to the question. how do i let jquery know which page is the current one he is visiting? ive got 3 php-pages.
if there is something you dont understand, please free to ask.
or if you got suggestions of other solutions, let me know. but i really want to display the registration box right away without redirecting him to another page.
You can set cookies initially in php and then update/read them via js.
You could assign the page to a session and do it that way.
$_SESSION["page_visited"] = "x.php";
Make sure to use session_start on the pages using sessions. Then just redirect to the relevant page.
header('Location: http://www.example.com/'$_SESSION["page_visited"]);
I did a similar thing not two weeks ago, correct me if I'm wrong, but if you want the registration to direct to the page the user was on, after the user has been registered in the ajax just add:
window.location.href=window.location.href;
That way the after the registration is done, it just reloads where the member was with the environment of a logged in user. This method worked great for me.
Related
I'm using WordPress with the plugin bbPress.
So far, so good.
The only thing I'm stuck at, is the fact that for certains functions to appear (like Approve Reply, Close Topic etc.) I need to refresh the page, otherwise the buttons won't appear.
How can I implement a sort of a function in order to refresh the current page just after I clicked on it?
So that basically when I enter this page, it gets automatically refreshed (and so the buttons will appear).
Thank you!
You can use header function this way:
header('Location:'.$_SERVER['REQUEST_URI']);
Good day, as the title says, how can I do that? What I'm trying to do is that on page 1, I looped all data with each having a button that has value of their specific id, then that button redirects to a common page 2, then I use that id on page 2 to display their whole data, but the problem is that when I refresh, the dialog appears.
I tried using session, but the problem is that when multiple tabs are accessing it.
I haven't really tried PRG, but on my understanding, it is used to send changes to the server using another page, then redirect to the previous page, preventing the dialog when refreshing. I thought of using it, but I don't know how to send the fetched data from page 1.5 to page 2
I'd be really grateful for a solution to this, or if someone can link me to similar problems. Maybe this is a duplicate question, but I just can't find the term for my problem. Cheers!!
If you control both pages, change the redirect mechanism on page 1 to GET by simply redirecting to a URL with a parameter appended to the address: target.php?id=42.
If you control only page 2, you may convert a POST request with an id to a GET request:
if (isset($_POST['id']))
{
header('Location: target.php?id=' . $_POST['id']);
exit;
}
More on GET vs POST here, as well as a couple of other answers.
How can I use php to echo a page instead of linking to existing html page with hyperlink?
One example would be
<html>
<body>
click on this link to go back
</body>
</html>
Now, I don't want this link above to be a link to html page but to echo a page with php code when user clicks on click on this link to go back(to generate a page). This way, nobody can access a page after they logout.
Can php do this?
If someone logged out of your website or application I assume you will have a check whether or not this person is allowed to view the content.
Your question itself is very unclear to me. But it sound a bit if you want to do client-side coding (don't follow a link when it's clicked) with PHP which is not possible since PHP is a server side language. You will need Javascript to change the behavior of a link (for example, make an AJAX request which returns the content of another page).
Create a function, what the function should do is it should get triggered on a button click event and the code inside the function must send an curl request to the url you want and get back the html from it and echo it on your page
For answering the second part of your question!. you want no one to access the data without logging in so maintain $_SERVER['']; and sessions for users and validate if the user is inside a genuine session then show him content else no
I am facing pretty specific problem right now. I am redoing a forum so there are reply buttons even though the user is not logged in. I am using Kunena. When user who is not logged in clicks the button a Core Design login popup will pop up and after the login the user will be redirected to the reply page.
Now I have this all working except one thing. I am not able to pass the correct redirect address to each of the modules.
Here is the code the render the plugin, I am passing the message id variable (different for each comment and crucial to get to go to correct reply page) :
jimport( 'joomla.application.module.helper' );
$module = &JModuleHelper::getModule('mod_cdlogin');
echo $this->message->id;
$attribs = array('comment_id'=>$this->message->id);
echo JModuleHelper::renderModule($module,$attribs);
This is inside a foreach loop for each comment on the page. The reply address is:
forum/forum-category-alias/2141-topic-alias/reply/2889.html
The last number being the ID is crucial for me. I am not able to pass this id to the module. I am but only the first one 2889 gets through. All of the login form modules has this same id, even though it should be higher.
So my question is: why does this module gets the same ID every time it is rendered? Cache somewhere? I have run out of options. Thanks for your help!
Hello how can I have a popup box like fancybox but to be appeared only one time per visitor based on a cookie?
Thank you for ideas and examples.
Well, you could have fancybox as you seem like it (me too by the way) along with a jquery cookie plugin. So you would check if the user has a cookie and if not show the fancybox, otherwise set the cookie so that if the same user reloads the page there is no fancy stuff happening.