0

I have an index.php page containing all recipes, where each recipe has an anchor tag to add ingredients. When you click it takes you to http://localhost/recipes_book/add_ingredients.php?id=4, the id being the recipe id. You can add ingredients only from a dropdown list, if the ingredient you want to add is not within the list, you need to add it as ingredient in the database on new_ingredient.php page. After the ingredient is registered, it will appear in the dropdown list to add it as ingredient for each recipe.

My question is.... can I redirect the user to the recipe they were adding the ingredient in the first place after the ingredient has been added? I mean... the ingredients can also be added "generally" from index.php, and it takes you to the same new_ingredient.php page.

Is there any way I can say "if user was coming from http://localhost/recipes_book/add_ingredients.php?id=X, redirect to the same page in success of adding the ingredient, but if the user clicked add ingredient from index.php, I don't want to redirect them to any recipe page.

Am I explaining myself any clear at all? I am not placing any code because it is irrelevant here, the only think I want to know if there is any php function to say "if the user came from this page".

Thank you!

eve_mf
  • 795
  • 3
  • 12
  • 36
  • 1
    It seems you're looking for [HTTP_REFERER](http://stackoverflow.com/questions/16374704/php-how-to-get-referrer-url) – Mihailo Nov 25 '16 at 16:26
  • thanks!!! I just put HTTP_REFERER on google and I can see it is exactly it! Thank you! – eve_mf Nov 25 '16 at 16:28
  • There is `$_SERVER['HTTP_REFERER'];` but it can not guarantee anything. It's safer you save the unique id in the session and recognize it by your own code. – Andre Lee Nov 25 '16 at 16:29
  • Not a problem. Glad I could help you out. You must've been really unlucky to not come across it :) Oh and off-topic try to be a bit more concise with your questions. It's nice to see somebody put in effort while asking a question though. – Mihailo Nov 25 '16 at 16:30
  • Andre Lee I am not sure what you mean with "it can not guarantee anything", but I guess I am going to try to do it with the session, because I am not sure now how to bring that recipe id O__O. Mihailo, I know I am not concise, but it is because when I ask something is because I couldn't find the answer myself, so, I don't really know what I am asking for.... it is very frustrating :/ – eve_mf Nov 25 '16 at 16:34
  • 1
    since HTTP_REFERER can be [forged](http://stackoverflow.com/questions/3104647/how-to-spoof-http-referer). If you are going to do some important things and depends on it, don't. – Andre Lee Nov 25 '16 at 16:40
  • @eve_mf no need to be frustrated, the more you enjoy the problems you come across the more you will enjoy coding :) Yay problems! – Mihailo Nov 25 '16 at 16:56

0 Answers0