Jump to content

Question related to dynamic page and echo


g_p_java

Recommended Posts

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!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.