pingpong
pingpong

Reputation: 1247

problem with the php get function?

i want to pass this paramater topic to another page,

p.s. the page is loaded using jquery?

the url:

http://localhost/final/home.php#page2?topic=jquery

now, i want to echo the the topic on #page2

<h3 class="timeline"><?php echo $_GET["topic"]; ?> </h3>

but it deosnt echo, any solutions, sorry for the newbiw questions :))

load_page.php

<?php
if(!$_POST['page']) die("0");

$page = (int)$_POST['page'];

if(file_exists('pages/page_'.$page.'.php'))
include('pages/page_'.$page.'.php');  // i.e page_2.php

else echo 'There is no such page!';
?>

Upvotes: 4

Views: 212

Answers (4)

Addo Solutions
Addo Solutions

Reputation: 1637

Just use PHP's parse_url function to do something like this:

$url = 'http://username:password@hostname/path?arg=value#anchor';
//Replace the URL in your case with "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH)

Which will return:

Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)
/path

In your case it would be more like:

Array
(
    [scheme] => http
    [host] => localhost
    [path] => /final/home.php
    [query] => topic=jquery
    [fragment] => page2
)

Upvotes: 0

getaway
getaway

Reputation: 8990

remove the php from dataType, and read this read this about datatypes for ajax requests

Upvotes: 1

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146450

To practical effects, a URL ends at #. Anything else is not even sent tot he server.

You probably want this:

http://localhost/final/home.php?topic=jquery#page2

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630409

Your URL needs to be like this:

http://localhost/final/home.php?topic=jquery#page2

Anything after the hash (#) isn't sent by the browser, it's purely for the browser, e.g. scrolling to the correct location, a way to do AJAX history, etc...but it's not sent in the request, currently all your server is getting is:

http://localhost/final/home.php

Which explains why _GET["topic"] is empty.

Upvotes: 7

Related Questions