jarrett000 Posted February 15, 2009 Share Posted February 15, 2009 Ok, i have a site where you put your name in a text box on the first page then redirects you to the homepage on submit(This one). On the homepage it'll say "Welcome <?php $_GET['name'] ?>" and that usually works. However, when the user loads the page without inputing their name the page will reload and anywhere the was <?php $_GET['name'] ?> is now blank(As you can see here). Can anyone help? Link to comment Share on other sites More sharing options...
mohammad_molana Posted February 15, 2009 Share Posted February 15, 2009 you can use of trim() function.trim() delete all space char from word's left and right. $name = trime($_GET['name']); and use isset() if(!isset($_GET['name'])){ header("location: index.php");} Link to comment Share on other sites More sharing options...
jlhaslip Posted February 15, 2009 Share Posted February 15, 2009 Use an if statement to check to see whether the page has been submitted with a GET valuefor 'name' or not.Substitute a Default value for the name when the GET is empty. Link to comment Share on other sites More sharing options...
jeffman Posted February 15, 2009 Share Posted February 15, 2009 It sounds like you want your script to remember the users name. You are correct the cookies is the way to go about that. Investigate the setcookie() function and the $_COOKIE array. Any cookies you have set on a client browser are automatically sent back to your server every time a client loads your document, so you just have to look in $_COOKIE to find them. Link to comment Share on other sites More sharing options...
jarrett000 Posted February 15, 2009 Author Share Posted February 15, 2009 I've tried that already, mohammad molana, but problem is that i got an error message that says:Warning: Cannot modify header information - headers already sent by (output started at /home/reaperw1/public_html/Jarrettcode.com/Home.php:3) in /home/reaperw1/public_html/Jarrettcode.com/Home.php on line 10 Link to comment Share on other sites More sharing options...
jeffman Posted February 15, 2009 Share Posted February 15, 2009 That happens when you've already output ANYTHING. There can be zero echo statements or html sections before the header() call. An html section is anything before or between <?php ?> tags, including line breaks and blank spaces, even if there are no visible characters. Anyone who writes PHP has been burned like that at least once. Link to comment Share on other sites More sharing options...
jarrett000 Posted February 15, 2009 Author Share Posted February 15, 2009 Thx, i moved it to before the <html> tag and it worked! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.