g_p_java Posted January 26, 2009 Share Posted January 26, 2009 Hello, i would like to make a general question as far as dynamic web pages are concerned. I would like my web page to change dynamically, so i'm using php. I would like also the page to show some unique information to every IP address that accesses the dynamic web page. For example, IP 1.2.3.4 visits the page and i need to output a unique message to that IP. In order to do that I'm using echo. Is there any other way to insert data in a web page in such a way, that only the user who accesses the page can see it? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 Well, you need to use some sort of logic (like an IF statement): <?php echo "This message is for everyone"; if($_SERVER["REMOTE_ADDR"] == '1.2.3.4'){ echo "This is a message just for you"; } ?> that is a very basic example...you can grow that to be as complicated as you want Quote Link to comment Share on other sites More sharing options...
g_p_java Posted January 26, 2009 Author Share Posted January 26, 2009 Well, you need to use some sort of logic (like an IF statement): <?php echo "This message is for everyone"; if($_SERVER["REMOTE_ADDR"] == '1.2.3.4'){ echo "This is a message just for you"; } ?> that is a very basic example...you can grow that to be as complicated as you want Yeah, thanks, It's just that i have to output a random message for each client, so that means that my code should look like that: <?php echo "This message is for everyone"; $ip = $_SERVER["REMOTE_ADDR"] ){ //a function that produces a random string $random echo "This is a message just for you $random"; } ?> Is that code going to appear a different message to everyone? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 does the message have to be different, or are you just looking to show the IP in the message? Quote Link to comment Share on other sites More sharing options...
g_p_java Posted January 26, 2009 Author Share Posted January 26, 2009 does the message have to be different, or are you just looking to show the IP in the message? Well i need to have a different string, but i have already that function that produces that random string. It's just that i wanna be sure that if 2 people access the web page at the same time, they are gonna see different/random messages , e.g. Guest A is not going to be able to see what message has been generated for Guest B. General Question : Does echo generate something dynamically in a page so that only the person that visits the page sees it? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 echo does not...it prints out whatever you tell it to print out. but if you have a function that generates a random string, every time the page is loaded (by the same person or by someone else) it will run that function and echo another random string. granted, it may randomly select the same string twice in a row though Quote Link to comment Share on other sites More sharing options...
g_p_java Posted January 26, 2009 Author Share Posted January 26, 2009 echo does not...it prints out whatever you tell it to print out. but if you have a function that generates a random string, every time the page is loaded (by the same person or by someone else) it will run that function and echo another random string. granted, it may randomly select the same string twice in a row though But generally when someone would like to generate something in a website, does he/she have to use echo, cause in the page i have to make, i need to generate something unique to every client IP address. Is there any other way to generate at the moment sm visits the page sthg, instead of using echo? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 how else do i explain this...echo is just for printing something...that something is whatever you tell it. you can via other methods doing something random...or even something unique... rand() for instance returns a random number: echo rand(1,100); the above will print a random number between 1 and 100 can you give a more detailed example of what you are trying to accomplish? so for example, a user with IP 1.2.3.4 visits your site...what should they see? then user with IP 5.6.7.8 visits...what should they see? Quote Link to comment Share on other sites More sharing options...
g_p_java Posted January 26, 2009 Author Share Posted January 26, 2009 how else do i explain this...echo is just for printing something...that something is whatever you tell it. you can via other methods doing something random...or even something unique... rand() for instance returns a random number: echo rand(1,100); the above will print a random number between 1 and 100 can you give a more detailed example of what you are trying to accomplish? so for example, a user with IP 1.2.3.4 visits your site...what should they see? then user with IP 5.6.7.8 visits...what should they see? User 1.2.3.4 shall see "Hello!" (or a random number e.g. 5) User 5.6.7.8 shall see "Good morning" (or e.g. 99) What i would like my program to accomplish is : Whenever someone(human or script) visits my webpage, the page has to make and insert at that specific moment a random string or number(they have to be unique for every IP) so that only that specific client can see them. My question is : Is echo a good choice for inserting data in a web page? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 My question is : Is echo a good choice for inserting data in a web page? wel....yes echo is used for printing something in a webpage, but echo won't magically do everything else you describe. Do you understand that part? Quote Link to comment Share on other sites More sharing options...
g_p_java Posted January 27, 2009 Author Share Posted January 27, 2009 My question is : Is echo a good choice for inserting data in a web page? wel....yes echo is used for printing something in a webpage, but echo won't magically do everything else you describe. Do you understand that part? "but echo won't magically do everything else you describe", Yes i know, it's just that i was wondering if there is another option in php for printing data in a web page except for echo. It's just that i would like to insert data dynamically in a web page and i was wondering if only echo can insert data in the web page. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 um...echo, print, or just stopping PHP: Here is some text before <?php echo "Hello World!"; print "Another Hello World!"; ?> Here is some more text <?php echo "...and the end"; ?> Quote Link to comment Share on other sites More sharing options...
g_p_java Posted January 27, 2009 Author Share Posted January 27, 2009 Ah ok, so echo or print. Hm...well everything seems fine now! Thanks a lot! 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.