njb182 Posted May 21, 2008 Share Posted May 21, 2008 I'm not very experienced with php yet and i need to develop a code for my website that goes something like this: If your on the page "www.website.com/en/light.php" then show the light image. If your on the page "www.website.com/en/dark.php" then show the dark image. Ya get what im trying to do? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 21, 2008 Share Posted May 21, 2008 What does that have to do with PHP? Those are two separate pages, so you do not need any programatical differences to show the different images. They can be statically defined in the HTML if you so choose. Now, if you used a single page and passed a variable to determine the image to show, then your questino would be relevant. Examples: www.website.com/en/page?type=light www.website.com/en/page?type=dark Quote Link to comment Share on other sites More sharing options...
njb182 Posted May 21, 2008 Author Share Posted May 21, 2008 What does that have to do with PHP? Those are two separate pages, so you do not need any programatical differences to show the different images. They can be statically defined in the HTML if you so choose. Now, if you used a single page and passed a variable to determine the image to show, then your questino would be relevant. Examples: www.website.com/en/page?type=light www.website.com/en/page?type=dark Ah! Sorry, i should of explained farther. I have the index file alright. And in there is a a php_require to the file which i want a script to do what im asking. Quote Link to comment Share on other sites More sharing options...
947740 Posted May 21, 2008 Share Posted May 21, 2008 So you want to know how to change the color? Use $_GET['type'] to get the color. <?php $type = $_GET['type']; if($type == "light") { $color = "tan"; // Some light color } else if($type == "dark") { $color = "black"; // Some dark color } else { $color = "white"; // Normal color } echo <<<END <html> <head> <title></title> <style type='text/css'> body { background-color: $color; } </style> </head> <body> </body> </html> END; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 21, 2008 Share Posted May 21, 2008 You don't state how you are passing the value to your index page, but I will assume it is sent on the URL as in my example above. <?php //Light will be the default if no value (or invalid value) passed $page_type = ($_GET['type']=='dark') ? 'dark.php' : 'light.php' ; require($page_type); ?> Quote Link to comment Share on other sites More sharing options...
njb182 Posted May 21, 2008 Author Share Posted May 21, 2008 So you want to know how to change the color? Use $_GET['type'] to get the color. <?php $type = $_GET['type']; if($type == "light") { $color = "tan"; // Some light color } else if($type == "dark") { $color = "black"; // Some dark color } else { $color = "white"; // Normal color } echo <<<END <html> <head> <title></title> <style type='text/css'> body { background-color: $color; } </style> </head> <body> </body> </html> END; ?> Close but no. I want it to get an IMAGE. Quote Link to comment Share on other sites More sharing options...
njb182 Posted May 21, 2008 Author Share Posted May 21, 2008 You don't state how you are passing the value to your index page, but I will assume it is sent on the URL as in my example above. <?php //Light will be the default if no value (or invalid value) passed $page_type = ($_GET['type']=='dark') ? 'dark.php' : 'light.php' ; require($page_type); ?> No it's not. Its linked by a require_once statement in the index page. Quote Link to comment Share on other sites More sharing options...
947740 Posted May 21, 2008 Share Posted May 21, 2008 If you want an image, just change the code so it refers to the image. Quote Link to comment Share on other sites More sharing options...
njb182 Posted May 21, 2008 Author Share Posted May 21, 2008 If you want an image, just change the code so it refers to the image. How? Im a n00b with PHP. Sorry. Quote Link to comment Share on other sites More sharing options...
947740 Posted May 21, 2008 Share Posted May 21, 2008 Ah. <?php $type = $_GET['type']; if($type == "light") { $color = "<img src='light.JPG' />"; } else if($type == "dark") { $color = "<img src='dark.JPG' />"; } else { $color = ""; } echo <<<END <html> <head> <title></title> </head> <body> $color </body> </html> END; ?> Quote Link to comment Share on other sites More sharing options...
njb182 Posted May 21, 2008 Author Share Posted May 21, 2008 Ah. <?php $type = $_GET['type']; if($type == "light") { $color = "<img src='light.JPG' />"; } else if($type == "dark") { $color = "<img src='dark.JPG' />"; } else { $color = ""; } echo <<<END <html> <head> <title></title> </head> <body> $color </body> </html> END; ?> Do I have to use that "type" stuff. I don't want to alter the url at all. I just want it to show the light image if your viewing light.php and dark image for dark.php. Quote Link to comment Share on other sites More sharing options...
947740 Posted May 21, 2008 Share Posted May 21, 2008 No you do not. <?php $type = $_SERVER['PHP_SELF']; // Get the filename if($type == "light.php") { $color = "<img src='light.JPG' />"; } else if($type == "dark.php") { $color = "<img src='dark.JPG' />"; } else { $color = ""; } echo <<<END <html> <head> <title></title> </head> <body> $color </body> </html> END; ?> However, that is utterly pointless, as mjdamato said. In light.php, just show the light image, and on dark.php, just show the dark image. Quote Link to comment Share on other sites More sharing options...
njb182 Posted May 21, 2008 Author Share Posted May 21, 2008 No you do not. <?php $type = $_SERVER['PHP_SELF']; // Get the filename if($type == "light.php") { $color = "<img src='light.JPG' />"; } else if($type == "dark.php") { $color = "<img src='dark.JPG' />"; } else { $color = ""; } echo <<<END <html> <head> <title></title> </head> <body> $color </body> </html> END; ?> However, that is utterly pointless, as mjdamato said. In light.php, just show the light image, and on dark.php, just show the dark image. Do i have to change the PHP_SELF to anything? Quote Link to comment Share on other sites More sharing options...
947740 Posted May 21, 2008 Share Posted May 21, 2008 No. Leave it like that. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 21, 2008 Share Posted May 21, 2008 Do I have to use that "type" stuff. I don't want to alter the url at all. I just want it to show the light image if your viewing light.php and dark image for dark.php. I understand you may be new to PHP, but you are making this much harder than it needs to be by not being very specific. I will state what I think you are trying to do based upon the previous posts. You have two different php files (light.php and dark.php) which determine the background image to show in an index page. You want some logic to determine which file to include using a require_once() function. However, you have not stated "HOW" you are going to determine the value to use to make that choice. I had made an assumption previously that you would pass a value on the URL when calling the index page, such as www.mydomain.com/index.php?type=light In that assumed example the index.php page would hold the content, and the dark.php and light.php scripts wouold be used to detemine the image to show on index.php (as in my first code example above). In the index.php page: <?php //Light will be the default if no value (or invalid value) passed $page_type = ($_GET['type']=='dark') ? 'dark.php' : 'light.php' ; require_once($page_type); ?> However, some statements you have made can be interpreted to mean that dark.php & light.php are two completly different pages - in which case all of this is unnecessary. If the user calls light.php then they will see what's in that page, the same for dark.php. Me: You don't state how you are passing the value to your index page, but I will assume it is sent on the URL as in my example above. You: Its linked by a require_once statement in the index page. That didn't answer the question. Another option that you might not be describing correctly is that you might have the user call dark.php or light.php and each of those pages does a require of the index page. But, again there really isn't enough information to provide relevant help. 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.