1

i want to make my index page display the current quarter and year so it will get updated as time goes by. i need help on reconstructing my code. here it is. its like a bulletin board calendar of some sort:

$now   = new DateTime();
    $month = (int)$now->format("m");
            $get_year = date("Y");

    if ($month >= 1 AND $month <= 3) {
       include_once("../index.php?year=".$get_year."&quarter=Q1");  
    }
    elseif ($month >= 4 AND $month <= 6) {
         include_once("../jet/index.php?year=".$get_year."&quarter=Q2");  
    }
    elseif ($month >= 7 AND $month <= 9) {
          include_once("../jet/index.php?year=".$get_year."&quarter=Q3");  
    }
    else {
         include_once("../jet/index.php?year=".$get_year."&quarter=Q4");  
    }

the page that would be displayed are ready, its just that i cant display it and results to these errors:

Warning: include_once(.../index.php?year=2012&quarter=Q3) [function.include-once]: failed to open stream: Result too large in D:\xampp\htdocs\jet\index.php on line 121

Warning: include_once() [function.include]: Failed opening '.../index.php?year=2012&quarter=Q3' for inclusion (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\jet\index.php on line 121

help anyone?

8
  • 4
    Possible duplicate stackoverflow.com/questions/8301552/… Commented Aug 14, 2012 at 6:34
  • Go through this post stackoverflow.com/questions/5509929/… Commented Aug 14, 2012 at 6:36
  • 1. what do you have on line 121 in index.php ? Commented Aug 14, 2012 at 6:37
  • @IonutFlaviusPogacian include_once("../jet/index.php?year=".$get_year."&quarter=Q3"); Commented Aug 14, 2012 at 6:40
  • 1
    @IonutFlaviusPogacian What he wants is already answered by me and header() will not put an infinite loop. Commented Aug 14, 2012 at 6:52

2 Answers 2

3

Difference.

Let us get back to basics, shall we?

What you send via URL to receive as "GET" on the other side, it requires to be sent as HYPERTEXT to the webserver which will pass the information to PHP Scripts, which will COMPILE them accordingly. So, this logic will not work, because in include you play with FILE SYSTEM.

What you want to do is use header()

header("location: http://example.com/jet/index.php?year=$get_year&quarter=Q2");

instead of

include_once("../index.php?year=".$get_year."&quarter=Q1"); 

header() will redirect user as an HTTP response.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks! this worked. i just realized how noob i am of forgetting the header function. thanks again!
This will not include the script, this will redirect the server to another script.
@MinaYoussef and that is what will be achieved what Jet has been trying to do :)
This achieved what Jet wanted, but Jet tried to include a script. The difference between header and include is clear.
0

Do not pass $_GET variables in include string.

Get the variables ready

$year='2012';
$quarter='Q3';
include_once('index.php');

Then run the include string, you can access the year and quarter normally. Make sure to check the scope of the variables.

So your full code:

$year=$get_year;
if ($month >= 1 AND $month <= 3) {
   $quarter='Q1';
   include_once("../index.php");  
}
elseif ($month >= 4 AND $month <= 6) {
   $quarter='Q2';
   include_once("../jet/index.php");  
}
elseif ($month >= 7 AND $month <= 9) {
   $quarter='Q3';
   include_once("../jet/index.php");  
}
else {
   $quarter='Q4';
   include_once("../jet/index.php");  
}

4 Comments

i dont think that this is what he wants; he is in index.php, how can he include index.php again ? it will be an infinite loop
He did not mention which script is including which. But he was already including index.php, which is apparent from the error. Warning: include_once(.../index.php?year=2012&quarter=Q3)
i want to change the index page dynamically as soon as the date changes year and month. your answer seems like it the index would be static since the variables are defined, not based on the date function.
You can again specify the variables in each If statement. Check the updated code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.