Load a page relatively

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Idiot88
New php-forum User
New php-forum User
Posts: 19
Joined: Thu Jan 25, 2018 2:56 pm

Thu Feb 15, 2018 5:36 pm

Hi

I have a php script that needs to replace the current page with a page on the same website. What is the best way to load another page, relatively?

Thanks.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Thu Feb 15, 2018 6:25 pm

There is rarely a best since best is a relative term.

Explain what you mean by 'replace', it sounds like black hat nonsense.

Idiot88
New php-forum User
New php-forum User
Posts: 19
Joined: Thu Jan 25, 2018 2:56 pm

Thu Feb 15, 2018 6:37 pm

When you follow a link on a web page, your browser loads a new page. What is the php way to do this?

User avatar
zaim
New php-forum User
New php-forum User
Posts: 29
Joined: Sat Jan 06, 2018 9:05 am
Location: Kedah, Malaysia.

Fri Feb 16, 2018 1:22 am

Hello,

does it means the same URL with different page, isn't it?

If it is, you can just apply 'header' whenever a button is clicked. Using the same URL, you can add '?' (Query String) at the end of the URL and use a safe value from $_GET (that the user might have saved such as variable).

Example,
Initially, www.example.com/example.php
Then, www.example.com/example.php?varclicked=1

There is another method, which is using CSS, push the current web browser to the back by using z-index and show the user the new page you wanted them to see (initially, make it hidden). Of course, this will take you some time as it will be a lot to take under consideration. :)
Sorry if my answers aren't top notch but I will try my best to help anyone in need. :oops:

Idiot88
New php-forum User
New php-forum User
Posts: 19
Joined: Thu Jan 25, 2018 2:56 pm

Fri Feb 16, 2018 5:34 am

Sorry, I didn’t explain clearly. I am trying to do a very simple thing. For example, my website has 2 pages:

page1.php - a form.
page2.php - shows what the user has selected.

When the user is looking at page1 and clicks submit, I want page2 to be displayed. I have a handler function that checks the value of:

Code: Select all

  if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Need code here to display  page2.php 
  }
What must I do to display page2.php?

User avatar
zaim
New php-forum User
New php-forum User
Posts: 29
Joined: Sat Jan 06, 2018 9:05 am
Location: Kedah, Malaysia.

Fri Feb 16, 2018 6:49 am

Hello,

You can try;

Code: Select all

header("Location: page2.php");
Sorry if my answers aren't top notch but I will try my best to help anyone in need. :oops:

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Fri Feb 16, 2018 7:42 am

You're about to venture down a rocky road, form handling and re-directing are quite difficult to get to grips with, especially for a beginner, and you won't get a simple answer on a forum except for tweaking your knowledge.

I suggest you start here and work your way through ALL of it, try their methods out, and then see how you can make it fit in with what you want to do.

Post Reply