Cyonis Posted January 16, 2014 Share Posted January 16, 2014 (edited) I have a certain function on my webpage. Currently it does a few things, and then sends the user to another page and then that page directs to index.php. I want to change this function to refresh the current page (it must work on all pages, so can't use an url) without any actions set. How can I do this? Edited January 16, 2014 by Cyonis Quote Link to comment Share on other sites More sharing options...
requinix Posted January 16, 2014 Share Posted January 16, 2014 By not "send[ing] the user to another page and then to index.php". As in don't do the redirect you apparently have in place right now. Without the redirect the page will load again. Just make sure this "action" thing doesn't get set, whatever that means. Quote Link to comment Share on other sites More sharing options...
Cyonis Posted January 16, 2014 Author Share Posted January 16, 2014 I mean that I don't want to automatically redirect the user to index.php, but to the same page without any actions set or whatever the name is. I want it to kind of refresh the page and instead of resulting in url/pagename.php?action=logout for example, it should send it to url/pagename. But it has to work for all my pages because all pages use this script. Function. Are script and function interchangeable? I'm sorry if I'm not very clear, just started php 2 days ago :S Quote Link to comment Share on other sites More sharing options...
Cyonis Posted January 16, 2014 Author Share Posted January 16, 2014 By not "send[ing] the user to another page and then to index.php". As in don't do the redirect you apparently have in place right now. Without the redirect the page will load again. Just make sure this "action" thing doesn't get set, whatever that means. I've just read it again and yes, you actually just rephrased my question. How do I do this? Quote Link to comment Share on other sites More sharing options...
requinix Posted January 16, 2014 Share Posted January 16, 2014 Things happen in code because there is code to make the thing happen. Like a redirect. There is code to make the redirect happen. If you don't want the redirect to happen then you need to remove the code that does it. Yes I did restate your question, but that's because all I (thought I) needed to do to answer it: choose different words so that the question answered itself. I mean that I don't want to automatically redirect the user to index.php, but to the same page without any actions set or whatever the name is.Then, ironically, you need a redirect, except this time you redirect not to index.php but to the current page. And I think by "action" you mean the query string? What appears after the question mark in the URL? $_SERVER["REQUEST_URI"] contains everything in the URL after the hostname/domain name - including the query string. Such as "/pagename.php?action=logout". You can grab everything up to the query string with substr($_SERVER["REQUEST_URI"], strcspn($_SERVER["REQUEST_URI"], "?"))So redirect to that. However IMO a better course of action is to manually specify the URL. I know, manually sounds like a bad thing, but I can't imagine you have too many pages that need to do this redirect thing. ...all pages use this script. Function. Are script and function interchangeable?No, they're not. Not in the technical sense at least. A script is a file, like pagename.php, while a function is an actual function foo() { ... } you defined in code somewhere. Regarding action vs query string, like I said I think you were talking about the query string. An "action", when used in a web/technical context, probably means a form action (as in where the form submits its data to). ...Either that or an "action" in the MVC sense, where "MVC" is a design pattern for developing websites (where a "design pattern" is basically just a good way of solving a common problem), but you can find out about that later. Quote Link to comment Share on other sites More sharing options...
Cyonis Posted January 16, 2014 Author Share Posted January 16, 2014 Thanks, that's very clearly explained. I'm going to try this tomorrow! Quote Link to comment Share on other sites More sharing options...
requinix Posted January 16, 2014 Share Posted January 16, 2014 By the way, the thing I posted with substr() isn't quite right. Should be substr($_SERVER["REQUEST_URI"], 0, strcspn($_SERVER["REQUEST_URI"], "?")) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
× 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.