Jump to content

trying to get a variable added to a URL and reload page


james909

Recommended Posts

when my page is visited i am trying to get the page to reload with a random number variable added to the URL,

 

 

so if http://mysite.com/example/ is visited,

it reloads the page as either http://mysite.com/example/?outpost=1 or http://mysite.com/example/?outpost=2

 

 

this is the .PHP file http://mysite.com/example/index.php, i have commented to the side of the PHP code with what i am trying to achieve

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#" xml:lang="it">


<head>

<?php
$base_url = "http://mysite.com/example";     //this is actually the correct base link, to the url

$randompicstart=rand(1,2);         //gets a random number either 1 or 2

if (empty($_GET['v']))             //if variable v is empty then
{
$v=$randompicstart;                //assign the random number as variable v
}

if(!isset($_GET['outpost']))       //if the variable outpost is not in the url then
{
header("Location: $base_url/?outpost=$v");  //set the url with the outpost variable added as the value from v variable
exit;                                       //exit this url and reload new url which will have the outpost variable added
}

?>

</head>


<body>


<p>This is my HTML code for the page</p>


</body>


</html>

 

it is just returning a blank page and keeping the url the same, with no outpost variable added to the URL what is the problem with my code?
 
thank you for reading my problem, james
Edited by james909
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.