I need to reload or refresh the Page (index.php) at once on first time page loading. Because the google.com is giving the url to my page where there is no more data like index.php?id=10. So, I need to revert the url to index.php on first time only. I need solution in simple way. please any help?
Asked
Active
Viewed 425 times
0
-
Could you explain more deep what do you need? – Sergio Flores Feb 12 '16 at 19:12
-
Can you write a pieces of code and see where the challenge is? – Fas M Feb 12 '16 at 19:12
-
so ID decides which data is being displayed? Why don't you implement a correct handling for this, instead of redirecting just like that? - if you can't find data with ID - then redirect to base, otherwise fine. – axel.michel Feb 12 '16 at 19:19
-
for example if you call my page at first time with url like index.php?id=10. I need to revert the url to index.php. because if id==10. there is no more data in my page. but if id==9. data available in my page. so when they call my page. It shoul go to index.php only not with additional value. – yaseen ahmed Feb 12 '16 at 19:20
-
sir, there are lot of various result when user use search option in my page. So at first time only I don't want to show my Page without data. are you clear. – yaseen ahmed Feb 12 '16 at 19:23
-
Doesn't make sense. The purpose of GET variables is so that the page can be shared via url. If id=10, where 10 doesn't exist, then you can do what axel.michel suggested. If you don't want certain URLs to show up in search engines, simply [put it in robots.txt](http://stackoverflow.com/questions/9149782/ignore-urls-in-robot-txt-with-specific-parameters). – Dave Chen Feb 12 '16 at 19:36
-
Not only id sir. in search option there are location and many more. today something will be available. but tomorrow will not be available. according to their search result will be available are not. so I don't want to stop url in search engine. – yaseen ahmed Feb 12 '16 at 19:53
2 Answers
1
I'd recomend you use $_SESSION
global array, for it allows you to pass information from one page to another (or the same one, like in this case) easily. Be sure you initialize sessions on each page you use it, though.
The code should be something like this:
session_start(); //Important! Without this, $_SESSION doesn't work
//reload_index is a variable I'm using in the array, nothing restricted; you can use whichever name you like
if (!isset($_SESSION['reload_index']) || ($_SESSION['reload_index'] == 'yes'))
{
$_SESSION['reload_index'] = 'no';
header("Location: index.php"); //Or whatever page you want to go; you can add parameters as well, like index.php?id=10
}
//...Rest of the page
I hope this helps you resolve your problem. Best regards.

Ignacio Téllez
- 451
- 4
- 14
-
sir, I could not use session. because it is index.php there is no more session value. – yaseen ahmed Feb 12 '16 at 19:28
-
That shouldn't be a problem, @yaseenahmed, as long as you use `session_start();` at the beggining. – Ignacio Téllez Feb 12 '16 at 19:29
-
This, unless you CAN'T use $_SESSION for a technical restriction – Ignacio Téllez Feb 12 '16 at 19:30
0
Check if a flag is set in session. If not, set it and reload your page. Simple pseudo-code example:
session_start();
if (!isset($_SESSION['redirect_flag'])) {
$_SESSION['redirect_flag'] = true;
header("Refresh:0; url=index.php");
}

kano
- 5,626
- 3
- 33
- 48
-
sir, I need without session. because there is no more session value. – yaseen ahmed Feb 12 '16 at 19:29
-
sir this code gives error warning:Warning: Cannot modify header information - headers already sent by (output started at /home/nikahservi/public_html/index.php:1) in /home/nikahservi/public_html/index.php on line 6 – yaseen ahmed Feb 12 '16 at 19:35
-
That error is given when you are making a header redirect after already outputting some of the document. Meaning this code has to be before your `` tag – kano Feb 12 '16 at 19:51
-
thaks sir it is working after closed all browsers and reopen the page. but I have flaged another answer. thank so much. – yaseen ahmed Feb 12 '16 at 19:55