Jump to content

Header Glitch (or is it?)


WebCheez

Recommended Posts

The following block of code won't work.

$prob = $prob + 1;
$_SESSION['prob']=$prob;
header( 'Location: question' . $prob . '.php' );

This is just a small part of my script. I've made sure using print that $prob is 1 and is changed to 2. HOWEVER it gives me an error 404 page at question3, not question2.

I'm trying to make a quiz system.

Link to comment
Share on other sites

Using a series of pages named question1.php, question2.php, question3.php,... would be the hardest way of doing this because you are not making use of what php was designed for - letting php dynamically produce the web pages instead of you creating the web pages by hand.

 

You should be using a GET parameter on the end of the URL that indicates what action your single page of code does -

 

index.php?question=1

index.php?question=2

index.php?question=x

 

$_GET['question'] would have the value x when the page is requested.

 

As to your 404 error for the question3.php page, obviously you don't have a page in the current location by that exact name. Did you look at the file, checking for things like spelling errors and if you created your file using a Windows supplied editor, are you sure your file does not have a hidden .txt extension?

Link to comment
Share on other sites

Using a series of pages named question1.php, question2.php, question3.php,... would be the hardest way of doing this because you are not making use of what php was designed for - letting php dynamically produce the web pages instead of you creating the web pages by hand.

 

How else would I do this? I do need all of the radio button options, and the question itself.

MySQL?

 

As to your 404 error for the question3.php page, obviously you don't have a page in the current location by that exact name. Did you look at the file, checking for things like spelling errors and if you created your file using a Windows supplied editor, are you sure your file does not have a hidden .txt extension?

 

It's trying to redirect to the wrong page, it's supposed to be redirecting to question2.php.

And yes.

Link to comment
Share on other sites

The code probably is redirecting to question2.php but the code on question2.php is probably redirecting to quesiton3.php due to an error in your logic or your browser is requesting question1.php twice and is using the content of the session variable + 1 to redirect to quesiton3.php What is the whole code on the quesiton1.php and question2.php pages?

 

How else would I do this?

 

^^^ I showed how you would use a GET parameter on the end of the URL for one page to provide a value to the code on that page that would be used to determine what action that page takes. You would typically use a database to hold the content for dynamically produces php pages and just query for the correct content to be displayed.

 

 

 

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.