Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNils Garland
18,416 PointsChanging Cookie Values In PHP
Hi! I am making a sort of pretend search engine where you enter anything in the input and it will return the searches in a browser. This works fine but I wanted to add the option of changing the browser you where searching on as the default was DuckDuckGo. I am currently trying to change it to google by the click of a button. But when I set the Cookie, and then I try to change it, nothing seems to happen with the value. here is my code. I have also tried and the Cookie is actually set.
PHP:
<?php
setcookie(
"browser",
"https://duckduckgo.com/?q=",
time() + (10 * 365 * 24 * 60 * 60)
);
$current_browser = "DuckDuckGo";
if(isset($_POST["browser_url"])) {
$new_browser_url = $_POST["browser_url"];
setcookie('browser', $new_browser_url, time() + (10 * 365 * 24 * 60 * 60), '/');
}
?>
HTML Form:
<form action="index.php" method="post">
<input type="hidden" name="browser_url" value="https://google.com/search?q=">
<button class="thumbnail" value="submit"><img src="google.jpg" width="100%"></button>
</form>