spacepoet Posted February 15, 2011 Share Posted February 15, 2011 Hello: I want to show a message only if the user gets to the page by another page (Is a "Create New Section" page that transfers to the Edit page). I thought this might work: <?php if ($_REQUEST['URL'] == 'a_websiteDataAdd.php') echo "<span class=\"textError\">Section successfully created!</span>" ?> but it does not ... Any ideas on this? Quote Link to comment https://forums.phpfreaks.com/topic/227700-request-url-to-show-a-message/ Share on other sites More sharing options...
cyberRobot Posted February 15, 2011 Share Posted February 15, 2011 I haven't used $_REQUEST['URL'] before, but what do you get if you try something like: <?php echo $_REQUEST['URL']; ?> I would image it will display the entire path and not just the file name. So if you adjust the if statement accordingly it might work. Quote Link to comment https://forums.phpfreaks.com/topic/227700-request-url-to-show-a-message/#findComment-1174353 Share on other sites More sharing options...
spacepoet Posted February 15, 2011 Author Share Posted February 15, 2011 Hi: No, it didn't work, unfortunately. Thanks for taking a stab at it. Quote Link to comment https://forums.phpfreaks.com/topic/227700-request-url-to-show-a-message/#findComment-1174397 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 First off $_REQUEST is just a way to grab the variable regardless of whether it's get or post. Second, your code that you posted 'will' work if it's done correctly. On the page that shows the link "Create New Section" set the URL as a get parameter. <a href='page.php?URL=correcturl">Create Section</a> Then in your section code page add this <?php if ($_REQUEST['URL'] == 'correcturl') { echo "<span class=\"textError\">Section successfully created!</span>"; } ?> Of course you have to be aware that just echoing out success doesn't mean it does anything with the database...you actually have to handle that part. Quote Link to comment https://forums.phpfreaks.com/topic/227700-request-url-to-show-a-message/#findComment-1174398 Share on other sites More sharing options...
spacepoet Posted February 15, 2011 Author Share Posted February 15, 2011 Hi: Forgot completely about getting a parameter! One small issue (but it's not a dealbreaker, but would be nice to clean-up): a_websiteDataAdd.php: header("Location: a_websiteData.php?id=id&URL=a_websiteDataAdd.php"); Goes to: a_websiteData.php: <?php if ($_REQUEST['URL'] == 'a_websiteDataAdd.php') { echo "<span class=\"textError\">Section successfully created!</span>"; } ?> This does work fine, but since it's now on the page used to edit and add content, when the form gets POST, it will write both messages: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') echo "<span class=\"textError\">Section successfully updated!</span>" ?> <?php if ($_REQUEST['URL'] == 'a_websiteDataAdd.php') { echo "<span class=\"textError\">Section successfully created!</span>"; } ?> The URL looks like: a_websiteData.php?id=id&URL=a_websiteDataAdd.php Any way to TRIM or REPLACE the "&URL=a_websiteDataAdd.php" off when the form gets submitted: <form method="post" action="<?php echo $PHP_SELF;?>"> <input type="hidden" name="POSTBACK" value="EDIT"> <input type="hidden" name="id" value="<?php echo $id; ?>"> ... </form> ?? Quote Link to comment https://forums.phpfreaks.com/topic/227700-request-url-to-show-a-message/#findComment-1174424 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.